Session changes done in application_Error rolled back after redirect

前端 未结 5 1537
感情败类
感情败类 2021-01-26 05:01

I have an asp.net application and I am trying to handle custom exception using Application_Error. It works nicely but I have new requirement to set the error data in Session obj

5条回答
  •  囚心锁ツ
    2021-01-26 05:49

    You could use the Cache and an appropriate naming strategy for your key, like this:

    protected void Application_Error(object sender, EventArgs e)
        {
            HttpContext.Current.Cache["error:" + Session.SessionID] = Server.GetLastError();
            Response.Redirect("Error.aspx");
        }
    

    in the Error.aspx page you ca read it like this:

    var error = Cache["error:" + Session.SessionID];
    

提交回复
热议问题