using System;
|
using System.Web;
|
using System.Web.Http;
|
using System.Web.Mvc;
|
using System.Web.Routing;
|
using System.Web.SessionState;
|
using Jp.ApiCam.App_Start;
|
using Jp.ApiCam.Infrastructures;
|
using Pcb.Common;
|
using Pcb.Common.Enum;
|
using Pcb.Infrastructure.Ioc;
|
|
namespace Jp.ApiCam
|
{
|
// 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
|
// 请访问 http://go.microsoft.com/?LinkId=9394801
|
/// <summary>
|
///
|
/// </summary>
|
public class MvcApplication : System.Web.HttpApplication
|
{
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public override void Init()
|
{
|
EnableSession();
|
base.Init();
|
}
|
|
#region 启用session
|
void EnableSession()
|
{
|
PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
|
}
|
private void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
|
{
|
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
|
}
|
#endregion
|
|
/// <summary>
|
///
|
/// </summary>
|
protected void Application_Start()
|
{
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
AreaRegistration.RegisterAllAreas();
|
WebApiConfig.Register(GlobalConfiguration.Configuration);
|
WebApiFilterConfig.RegisterGlobalFilters(GlobalConfiguration.Configuration.Filters);
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
var desc = GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions;
|
}
|
|
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
{
|
var ex = Server.GetLastError();
|
LogHelper.Error("UnhandledException", (Exception)e.ExceptionObject);
|
AppResponseMessageHelper.Error(EnumApiStatusCode.Error, ConfigUtils.IsProductionEnvironment ? "服务器或网络异常" : ex.Message);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void Application_Error(object sender, EventArgs e)
|
{
|
var ex = Server.GetLastError();
|
LogHelper.Error("Application_Error", ex);
|
//System.IO.File.AppendAllText(Server.MapPath("./")+"log.txt",ex.StackTrace + "\r\n" + ex.Source + "\r\n" + ex.Message);
|
AppResponseMessageHelper.Error(EnumApiStatusCode.Error, ConfigUtils.IsProductionEnvironment ? "服务器或网络异常" : ex.Message);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
protected void Application_BeginRequest()
|
{
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
protected void Application_EndRequest()
|
{
|
}
|
}
|
}
|