Web.config Custom Errors mode Conflict

79,141

Solution 1

When you're having issues with configuration, make sure that your settings isn't overridden.

In this case, your server might have a configuration <deployment retail="true" /> that overrides application settings and disables trace output, custom errors, and debug capabilities.

Change the value to "false"

<deployment retail="false" />

MSDN Link

Solution 2

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.

Solution 3

First, you can set CustomErrors mode from "RemoteOnly" to "off" <customErrors mode="Off"></customErrors>

Second, You can check the global.asax.maybe you create Response.Redirect as same as defaultRedirect in customError. you can check more detail in here ASP.NET customErrors with mode=remoteOnly and global.asax handling exceptions

and the last,maybe you create two system.web in your webconfig. You should only have one in your config file.please check again your webconfig. and dont forget <compilation debug="true"/>

Solution 4

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!

Solution 5

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.

Share:
79,141

Related videos on Youtube

Saeed
Author by

Saeed

C# , Asp.NET , Desgin Pattern , SQL Server , IIS Expert Senior IT Consultant at Twinsoft GmbH

Updated on March 24, 2020

Comments

  • Saeed
    Saeed about 4 years

    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

    • शेखर
      शेखर over 11 years
      custom error to on means your are creating your own page for error. Like 404 file not found etc. When you set it to off is shows the error to every one. And if it is remote only then from the same machine only error can be seen
    • शेखर
      शेखर over 11 years
      Are you throwing your error. Or you have written something in your global file Application_Error method?
    • Saeed
      Saeed over 11 years
      Thank you for comment,I know but i want see error for debug it,and dont show error
    • शेखर
      शेखर over 11 years
      also it would be helpful if you can show you current setting of web.config file
    • Simon Halsey
      Simon Halsey over 10 years
      It would seem to be ignoring the customerror settings, which could mean an unrelated error in your web.config. Check the file is formatted correctly, then try commenting sections out until it works.
    • Shashank Chaturvedi
      Shashank Chaturvedi over 10 years
      Is debugging set to true in your web.config? When you debug your application does it show localhost in the address bar?