可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
when I set mode to On,say Please set customErrors mode to On Again.
回答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
回答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.
回答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"/>
回答4:
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.
回答5:
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:
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.
回答7:
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?
回答8:
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.
回答9:
removing this line works for me!
<customError />
回答10:
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.
回答11:
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...