Web.config Custom Errors mode Conflict

前端 未结 11 1472
执笔经年
执笔经年 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:

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Throw Error" />
    

    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:

        <asp:Label ID="Label1" runat="server" Text=""></asp: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:

        <system.web>
          <customErrors mode="On" defaultRedirect="~/ErrorPage.aspx" redirectMode="ResponseRewrite" />
        </system.web>
    

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

    Happy coding!

    0 讨论(0)
  • 2020-12-25 13:30

    removing this line works for me!

    <customError  />
    
    0 讨论(0)
  • 2020-12-25 13:34

    I've never seen it say set to On. I've seen it say set customeErrors to off which will give you detailed errors. Set it to off and then add the actual error message you see to this post. Are you positive your not getting a different message like a 404 error?

    0 讨论(0)
  • 2020-12-25 13:34

    From what I can see, you don't have the <customErrors mode="Off" /> as the first node in the <system.web> node.

    If I were to guess, you have the customErrors node inside a <compilation targetFramework="x.x"> node.

    You probably have the applicationpool set to another version of the .NET framework than the application is written in. Make sure the <customErrors mode="Off" /> node is the first inside the <system.web> node, then it will most likely give you the detailed errormessage.

    0 讨论(0)
  • 2020-12-25 13:36

    Set the mode to On, save the web.config then refresh or restart the IIS and make sure the mode is still set to On after saved. Browse to it again, it should show the error...

    0 讨论(0)
  • 2020-12-25 13:39

    I just wanted to comment here, but I do not have enough point to comment, Can we see the actual, page that produces the error and see the entire web.config? you can blur out the connectionstrings and such so as not to give any passwords away.

    But with what I see,

    I think from what you are saying you are using IIS Express debugging on local machine. I would done IIS Express, or ctrl+F5 the page to see if the site is just not cached.

    setting the custom errors to Off will show you the debug message - NOTE the "O" in Off must be capitalized with lower case of the f's. looks like you have this, but worth mentioning

    Custom Errors Off - Specifies that custom errors are disabled. This allows display of detailed errors.

    0 讨论(0)
提交回复
热议问题