Web.config Custom Errors mode Conflict

2020-02-19 05:23发布

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 another error and I see this Message :

customErrors mode to Off or On Or RemoteOnly,

I set this property Off, but do not show error and say again please set attribute to On your CustomError.

enter image description here

enter image description here

when I set mode to On,say Please set customErrors mode to On Again.

enter image description here

enter image description here

11条回答
姐就是有狂的资本
2楼-- · 2020-02-19 05:55

To show the error for debugging and NOT showing an custom error page you do not need a defaultRedirect and simply having this should then output the debug / exception information:

<system.web>
    <customErrors mode="On" />
</system.web>

NOTE: Ensure that On starts with an upper-case O. By changing the web.config this should (by default) recycle your app pool and be picked up straight away.

查看更多
欢心
3楼-- · 2020-02-19 05:56

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...

查看更多
\"骚年 ilove
4楼-- · 2020-02-19 05:57

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.

查看更多
ら.Afraid
5楼-- · 2020-02-19 05:57

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!

查看更多
成全新的幸福
6楼-- · 2020-02-19 06:01

removing this line works for me!

<customError  />
查看更多
Luminary・发光体
7楼-- · 2020-02-19 06:05

Make sure you nest the customErrors tag somewhere inside your <system.web> tag like this:

<system.web>
<customErrors mode="Off" />
</system.web>

From your description it's already likely it was placed there by you or automatically generated another way. Also try setting to On and restart the Application pool. You can do this by simply modifying web.config file by adding a break return or even just hit the space key, as long as you've made a change. Now re-upload making sure this is your second time with the customErrors mode was set to On. Hopefully you can now view your custom error page.

If you are still having problems, and have access to your web site from IIS Manager try editing the .NET Error Pages in Features view. That will also do the same thing, providing your custom error page is in the correct directory for the web.config file to access.

查看更多
登录 后发表回答