forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandler.cs
More file actions
43 lines (39 loc) · 1.25 KB
/
Handler.cs
File metadata and controls
43 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Web;
using Newtonsoft.Json;
namespace SiteServer.CMS.UEditor
{
/// <summary>
/// Handler 的摘要说明
/// </summary>
public abstract class Handler
{
public Handler(HttpContext context)
{
Request = context.Request;
Response = context.Response;
Context = context;
Server = context.Server;
}
public abstract void Process();
protected void WriteJson(object response)
{
string jsonpCallback = Request["callback"],
json = JsonConvert.SerializeObject(response);
if (string.IsNullOrWhiteSpace(jsonpCallback))
{
Response.AddHeader("Content-Type", "text/plain");
Response.Write(json);
}
else
{
Response.AddHeader("Content-Type", "application/javascript");
Response.Write($"{jsonpCallback}({json});");
}
Response.End();
}
public HttpRequest Request { get; private set; }
public HttpResponse Response { get; private set; }
public HttpContext Context { get; private set; }
public HttpServerUtility Server { get; private set; }
}
}