62,046
社区成员
发帖
与我相关
我的任务
分享
public class MvcApplication : SpringMvcApplication // System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
#region
string fileLogPath = Server.MapPath("Log/");
ThreadPool.QueueUserWorkItem((a) => {
while (true)
{
if (MyExceptionAttribute.ExceptionQueue.Count > 0)
{
Exception ex = MyExceptionAttribute.ExceptionQueue.Dequeue();
string fileName = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
File.AppendAllText(fileLogPath + fileName, ex.ToString(), System.Text.Encoding.UTF8);
}else
{
Thread.Sleep(5000);
}
}
}, fileLogPath);
#endregion
}
namespace Andrew.Royal.WebApp
{
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// filters.Add(new HandleErrorAttribute());
filters.Add(new MyExceptionAttribute());
}
}
}
namespace Andrew.Royal.WebApp.Models
{
public class MyExceptionAttribute : HandleErrorAttribute
{
public static Queue<Exception> ExceptionQueue = new Queue<Exception>();
public override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
ExceptionQueue.Enqueue(filterContext.Exception);
//怎么都跳转不到这个页面
filterContext.HttpContext.Response.Redirect("/Error.html");
}
}
}
<system.web>
<customErrors mode="On" ></customErrors>
<!--defaultRedirect="/Error2.html"-->
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>