You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.5 KiB
134 lines
4.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Optimization;
|
|
using System.Web.Routing;
|
|
using System.Web.Security;
|
|
using System.Web.SessionState;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using CK.SCP.Utils;
|
|
using FineUI;
|
|
|
|
namespace SCP
|
|
{
|
|
public class Global : HttpApplication
|
|
{
|
|
|
|
protected void Application_Start(object sender, EventArgs e)
|
|
{
|
|
//
|
|
}
|
|
|
|
protected void Session_Start(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void Application_BeginRequest(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string _returnUrl = Request.QueryString["ReturnUrl"];
|
|
string _url = Request.RawUrl;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Response.Redirect("/", true);
|
|
}
|
|
}
|
|
|
|
protected virtual void Application_EndRequest()
|
|
{
|
|
var context = HttpContext.Current.Items["__AppBoxContext"] as AppBoxContext;
|
|
if (context != null)
|
|
{
|
|
context.Dispose();
|
|
|
|
}
|
|
}
|
|
|
|
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
{
|
|
Exception objExp = HttpContext.Current.Server.GetLastError();
|
|
if (objExp.Message.Contains("有潜在危险"))
|
|
{
|
|
String errorCode = Guid.NewGuid().ToString();
|
|
String errorMsg = objExp.InnerException == null ? objExp.GetBaseException().Message : objExp.InnerException.Message;
|
|
HttpContext.Current.Server.ClearError();
|
|
|
|
Response.Redirect("/", true);
|
|
Response.End();
|
|
Response.Clear();
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
String errorCode = Guid.NewGuid().ToString();
|
|
String errorMsg = objExp.InnerException == null ? objExp.GetBaseException().Message : objExp.InnerException.Message;
|
|
HttpContext.Current.Server.ClearError();
|
|
|
|
|
|
ShowError(errorCode, errorMsg, HttpContext.Current);
|
|
}
|
|
}
|
|
|
|
protected void Session_End(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void Application_End(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
private String BuildErrorString(string errorCode, HttpContext context)
|
|
{
|
|
Exception ex = context.Server.GetLastError();
|
|
System.Text.StringBuilder errorStr = new System.Text.StringBuilder();
|
|
if (ex != null)
|
|
{
|
|
errorStr.Append("{ErrorCode:");
|
|
errorStr.Append(errorCode);
|
|
errorStr.Append(",ErrorPage:");
|
|
errorStr.Append(context.Request.Url.ToString());
|
|
errorStr.Append(",ErrorMsg:");
|
|
errorStr.Append(ex.GetBaseException().Message);
|
|
errorStr.Append(",StackTrace:");
|
|
errorStr.Append(ex.StackTrace);
|
|
if (ex.InnerException != null)
|
|
{
|
|
errorStr.Append(",InnerErrorMsg:");
|
|
errorStr.Append(ex.InnerException.Message);
|
|
errorStr.Append(",InnerStackTrace:");
|
|
errorStr.Append(ex.InnerException.StackTrace);
|
|
}
|
|
errorStr.Append("}");
|
|
}
|
|
return errorStr.ToString();
|
|
}
|
|
|
|
private void ShowError(string errorCode, string errorMsg, HttpContext context)
|
|
{
|
|
HttpResponse response = context.Response;
|
|
System.Text.StringBuilder errorPage = new System.Text.StringBuilder();
|
|
errorPage.Append("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> <link href=\"res/css/error.css\" rel=\"stylesheet\" type=\"text/css\" /></head><body>");
|
|
errorPage.Append("<div style='margin:5px;border:1px solid #DDCCDD;padding:5px;'><p><strong>错误代码:</strong>");
|
|
errorPage.Append(errorCode);
|
|
errorPage.Append("</p><p><strong>错误消息:</strong>");
|
|
errorPage.Append(errorMsg);
|
|
errorPage.Append("</p><p><strong>系统异常请重试,若重复出现请联系系统管理员!</strong></p></div></body></html>");
|
|
response.Write(errorPage.ToString());
|
|
response.End();
|
|
response.Clear();
|
|
}
|
|
}
|
|
}
|
|
|