|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Converters;
|
using System;
|
using System.Web;
|
using System.Web.SessionState;
|
|
public abstract class PageHandler<T> : IHttpHandler, IRequiresSessionState where T : ISessionObject
|
{
|
public bool IsReusable
|
{
|
get
|
{
|
return true;
|
}
|
}
|
|
public abstract JsonPageResult ProcessRequestInternal(PageContext<T> context);
|
|
public void ProcessRequest(HttpContext context)
|
{
|
PageContext<T> context1 = new PageContext<T>(context);
|
JsonPageResult jsonPageResult;
|
try
|
{
|
string @string = context1.GetString("action");
|
if (!context1.IsValid && @string != "login" && @string != "logout")
|
throw new Exception("由于长时间未操作,请重新登陆平台!");
|
jsonPageResult = this.ProcessRequestInternal(context1);
|
}
|
catch (Exception ex)
|
{
|
jsonPageResult = new JsonPageResult(false, (object)ex.Message);
|
}
|
IsoDateTimeConverter dateTimeConverter = new IsoDateTimeConverter();
|
dateTimeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
|
context.Response.ContentType = "application/json";
|
string s = JsonConvert.SerializeObject((object)jsonPageResult, Formatting.Indented, new JsonConverter[1]
|
{
|
(JsonConverter) dateTimeConverter
|
});
|
context.Response.Write(s);
|
context.Response.End();
|
}
|
}
|