24

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

Saeed
  • 3,415
  • 3
  • 24
  • 41
  • 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 – शेखर Nov 06 '12 at 07:25
  • 1
    Are you throwing your error. Or you have written something in your global file Application_Error method? – शेखर Nov 06 '12 at 07:27
  • Thank you for comment,I know but i want see error for debug it,and dont show error – Saeed Nov 06 '12 at 07:27
  • also it would be helpful if you can show you current setting of web.config file – शेखर Nov 06 '12 at 07:28
  • 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. – Simon Halsey Jan 19 '14 at 23:55
  • Is debugging set to true in your web.config? When you debug your application does it show localhost in the address bar? – Shashank Chaturvedi Jan 20 '14 at 04:48

11 Answers11

18

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

Ajeesh M
  • 2,092
  • 1
  • 14
  • 18
5

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.

Oddacon
  • 309
  • 6
  • 12
4

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"/>

Community
  • 1
  • 1
3

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.

Belogix
  • 8,129
  • 1
  • 27
  • 32
3

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!

Gregor Primar
  • 6,759
  • 2
  • 33
  • 46
1

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.

Lawrence Thurman
  • 657
  • 8
  • 15
1

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?

csaam
  • 1,349
  • 9
  • 9
1

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.

Stephen
  • 2,027
  • 2
  • 22
  • 26
1

removing this line works for me!

<customError  />
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
Milad
  • 719
  • 1
  • 10
  • 28
1

Many hosting companies actually override the settings from your web.config file by theirs. You can usually set these concrete attributes in the web host's dashboard for the website.

If you tell us the concrete web hosting you are using, we should be able to assist better with concrete steps.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
-1

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

firemonkey
  • 11
  • 3