OpenAuth.Net/OpenAuth.Mvc/Global.asax.cs

67 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Web;
2015-09-23 00:10:11 +08:00
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
2015-10-26 21:58:12 +08:00
using Infrastructure;
using Newtonsoft.Json.Linq;
using OpenAuth.Mvc.Controllers;
using OpenAuth.Mvc.Models;
2015-09-23 00:10:11 +08:00
namespace OpenAuth.Mvc
{
2015-11-13 23:25:46 +08:00
public class MvcApplication : HttpApplication
2015-09-23 00:10:11 +08:00
{
protected void Application_Start()
{
2015-10-26 21:58:12 +08:00
AutofacExt.InitAutofac();
2015-09-23 00:10:11 +08:00
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ModelBinders.Binders.Add(typeof(JObject), new JobjectModelBinder());
2015-10-26 21:58:12 +08:00
LogHelper.Log("启动Web");
2015-09-23 00:10:11 +08:00
}
2016-07-08 18:51:48 +08:00
protected void Application_Error(object sender, EventArgs e)
{
var app = (MvcApplication)sender;
var context = app.Context;
var ex = app.Server.GetLastError();
LogHelper.Fatal(ex.Message);
context.Response.Clear();
context.ClearError();
var httpException = ex as HttpException;
var routeData = new RouteData();
routeData.Values["controller"] = "error";
routeData.Values["exception"] = ex;
routeData.Values["action"] = "http500";
if (httpException != null)
{
switch (httpException.GetHttpCode())
{
case 404:
routeData.Values["action"] = "http404";
break;
case 401: //没有登录
routeData.Values["action"] = "http401";
break;
case 400: //演示版本,没有执行的权限
routeData.Values["action"] = "DemoError";
break;
}
}
IController controller = new ErrorController();
controller.Execute(new RequestContext(new HttpContextWrapper(context), routeData));
}
2015-09-23 00:10:11 +08:00
}
}