问题描述
尝试在使用 C# 中的 .Net 4.7.2 的 MVC 5.2.7 网站中进行一些全局错误处理。
Global.asax 中的这个方法在出现错误时调用正常;通过尝试访问不存在的页面来测试它。
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Error(object sender,EventArgs e)
{
Exception ex = this.Server.GetLastError();
Utility.LoggingUtility.LogAndEmailException(this.Response,this.Session,ex,this.Request);
}
}
public static class LoggingUtility
{
public static void LogAndEmailException(HttpResponse response,HttpSessionState session,Exception ex,HttpRequest request = null)
{
Utility.ErrorPageUtility.SetErrorPageMessage(ex,session,ex.Message);
response.Redirect("~/Error",false);
}
}
public static class ErrorPageUtility
{
public static void SetErrorPageMessage(Exception ex,string message)
{
session["ErrorTypeMessage"] = message;
}
}
当我在错误视图中尝试 this.Session["ErrorTypeMessage"] 时出现问题,即它始终为空。会话未更改(会话 ID 与设置时相同)但密钥已“消失”。
会话是默认的......即使用 cookie 的 InProc。
附言令人讨厌的是它在不同的项目中运行良好。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)