Web.config Custom Errors mode Conflict

前端 未结 11 1498
执笔经年
执笔经年 2020-12-25 12:52

I have a great and important problem with Web.Config, I need to see the Error of my page and resolve it in asp.net web form and web config, but when Error Occurred, I see an

11条回答
  •  情话喂你
    2020-12-25 13:30

    Here is sample code how you can display exceptions on custom page.

    First create Default.aspx with button:

        
    

    Add following code for button click event:

        protected void Button1_Click(object sender, EventArgs e)
        {
            throw new Exception("Sample Exception on my Page");
        }
    

    Second create ErrorPage.aspx with label:

        
    

    And code for error page:

        protected void Page_Load(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            if (ex != null && ex.InnerException != null)
            {
                Label1.Text = string.Format("An error occured: {0}", ex.InnerException.Message);
            }
        }
    

    And finally place following configuration in web.config:

        
          
        
    

    Compile and start with Default.aspx. Click your button and error will be shown on your custom page.

    Happy coding!

提交回复
热议问题