PageRenderTime 100ms CodeModel.GetById 97ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/source/app/NOS.Root/JSONPHandler.ashx

http://github.com/agross/netopenspace
Unknown | 52 lines | 45 code | 7 blank | 0 comment | 0 complexity | 8f036096f3313b0c0e5bdea1057bcefc MD5 | raw file
 1<%@ WebHandler Language="C#" Class="JSONPHandler" %>
 2
 3using System;
 4using System.IO;
 5using System.Web;
 6
 7public class JSONPHandler : IHttpHandler
 8{
 9	public void ProcessRequest (HttpContext context)
10	{
11		string callback = context.Request.QueryString["json"];
12		string file = context.Request.QueryString["file"];
13        
14        try
15		{
16			context.Response.ContentType = "text/javascript";
17			context.Response.AddHeader("X-Content-Type-Options", "nosniff");
18			context.Response.Cache.SetLastModified(File.GetLastWriteTimeUtc(context.Server.MapPath(file)));
19			context.Response.Cache.SetCacheability(HttpCacheability.Public);
20			context.Response.Cache.SetSlidingExpiration(true);
21			context.Response.Cache.SetExpires(DateTime.Now.AddDays(30));
22			context.Response.Cache.SetMaxAge(TimeSpan.FromDays(30));
23			context.Response.Cache.SetNoTransforms();
24			
25			if (!String.IsNullOrEmpty(callback))
26			{
27				//context.Response.Write("alert('hit');");
28				context.Response.Write(callback + "(");
29			}
30			
31			context.Response.TransmitFile(file);
32			
33			if (!String.IsNullOrEmpty(callback))
34			{
35				context.Response.Write(");");
36			}
37		}
38		catch(FileNotFoundException)
39		{
40			context.Response.Clear();
41			context.Response.StatusCode = 404;
42		}
43    }
44
45    public bool IsReusable
46	{
47        get
48		{
49            return true;
50        }
51    }
52}