Response.Redirect not working in Global.asax

前端 未结 1 1274
孤街浪徒
孤街浪徒 2021-02-19 13:20

I have created an error page to show a general message for all unhandled exceptions.

This is the code in Global.asax

HttpContext ctx = HttpContext.Curren         


        
相关标签:
1条回答
  • 2021-02-19 14:17

    Replace Response.Redirect("~/Error.aspx"); with:

    // You've handled the error, so clear it. Leaving the server in an error state can cause unintended side effects as the server continues its attempts to handle the error.
    Server.ClearError();
    
    // Possible that a partially rendered page has already been written to response buffer before encountering error, so clear it.
    Response.Clear();
    
    // Finally redirect, transfer, or render a error view
    Response.Redirect("~/Error.aspx");
    
    0 讨论(0)
提交回复
热议问题