ASP.NET Web.config debugging - asp.net

I've uploaded a working application to my hosting web server and one page that I was working throws an error. In my web.config I have setting like this:
....
<customErrors mode="Off" defaultRedirect="errorpage.htm">
<error statusCode="403" redirect="bannedaddress.htm" />
<error statusCode="404" redirect="filenotfound.htm" />
</customErrors>
<compilation debug="true" targetFramework="4.0">
....
and I am redirected to errorpage.htm even though customErrors mode is set to Off. I can't find any info about the error (other than it occured) in the log files.
The question is: what should I change to be able to debug the app?

Could be your IIS settings, depending on the host you may be able to access the IIS error files. It could be that your IIS is redirecting to that page and not your application.
Your customErrors should not be redirecting when the mode is off.

Is it a virtual application? In that case, you might want to set <customErrors mode="Off" /> on the parent directory aswell.

Related

Custom error page in "Release" mode and default error page in "Debug" mode

I want to show a custom error page when the project is in production (release mode) and show the default error page from asp.net when running the page in (debug mode).
I have three Web.config files in my project.
Web.config
Web.Debug.config
Web.Release.config
This is what I have tried but had no luck.
Web.config
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/Error" />
</customErrors>
Web.Debug.config
<customErrors mode="Off" xdt:Transform="Replace"></customErrors>
Web.Release.config
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/Error" />
</customErrors>
Does anyone know how I can do this?
Thanks in advance :)
Edit:
After reading around, I'm thinking that this is a known bug but I wasn't able to find a bug fix for this. If anyone knows more about this, please share. Thanks
Okay. So I figured out what was wrong.
Web.config
<customErrors mode="Off" defaultRedirect="~/Error.htm"></customErrors>
Web.Debug.config
<compile debug="true" />
<customErrors mode="Off" xdt:Transform="Replace"></customErrors>
Web.Release.config
<customErrors mode="On" defaultRedirect="~/Error.htm" xdt:Transform="Replace">
<error statusCode="404" redirect="~/Error.htm" />
</customErrors>
The changes above will keep error messages disabled by default and whenever the project is deployed on the production server, the settings in Web.Release.config will overwrite the default Web.config
Here is a list of resources / links that I found helpful:
Use Visual Studio web.config transform for debugging
http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx
I hope this helps anyone else that is trying to accomplish the same thing.
This is a know bug. That feature can be used right now only as part of the deploy process.
Please check this below post
How can I use Web.debug.config in the built-in visual studio debugger server?
or you could just use the 'default' web.config as your development/debugging version, and then the web.release.config would of course continue to be the release version, since its transforms are applied when you publish.
Hope it will help.

ASP.NET / Web.config: customErrors redirect only on a 404

I have this scenario:
A user comes to my site and follows a link, which doesn't exists anymore, he should be redirected to a custom errorpage. (that works)
If a user does something, that throws an error, he should see the Stacktrace and the real Errorpage.
This is my current Web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors>
<error statusCode="404" redirect="/errors/404.htm" />
</customErrors>
<compilation debug="true" strict="false" explicit="true" />
</system.web>
</configuration>
with this configuration, a 404 will be redirected to the right site, but a HTTP 500 will be shown as following:
Server Error in '/' Application
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web [.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
[...]
But in this case I want to show the stacktrace.
How can I do this?
Note: We're on Linux with a Mono <- FastCGI -> Lighttpd construction.
In the following web.config entries, a not found (404) condition will send a user to PageNotFound.aspx
Use mode="Off" and everyone (local and remote users) will see error details.
<customErrors mode="Off">
<error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>
Use mode="RemoteOnly" and local users will see detailed error pages with a stack trace and compilation details. Remote users with be presented with the GeneralError.aspx page
<customErrors mode="RemoteOnly" defaultRedirect="~/errorPages/GeneralError.aspx">
<error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>
Ray Van Halens Answer is correct, but this was not the actual problem.
The reason for not showing stacktrace is a bug in mono itself. There is no other way then write an own error page where the stacktrace is dispayed.

customErrors with redirectMode="ResponseRewrite" do not work on shared hosting

I am trying to setup custom error pages for my site (ASP.NET 4, integrated pipeline).
Everything works properly on local machine but custom error pages for .aspx pages do not get shown on shared hosting (I see default error pages).
If I change redirectMode="ResponseRewrite" to redirectMode="ResponseRedirect" everything works properly on local and shared machine.
error.aspx is a real file that resides next to web.config file (in the root of the site). Site has no Global.asax file.
Local machine runs IIS 7.5, I do not use routing (at least consciously) and shared hosting tells that Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319
Could you please tell me what might be the reason for such different behavior and what should I do to resolve the issue.
Here is excerpt from my web.config file:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/error.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On" defaultRedirect="error.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/error.aspx"/>
</customErrors>
<httpRuntime requestValidationMode="2.0" />
</system.web>
After loooong discussion with the hosting provider it turned out that:
my approach is fine
but it won't work as expected because hosting provider disabled such ability via machine.config.
So, never underestimate number of provider gotchas.
I have the following comment in my web.config:
for IIS 7.5, use errorMode="Custom"; use responseMode="ExecuteURL" if using routing, otherwise use responseMode="Redirect"
Just don't ask me to explain, because I don't know! I just sorted it out by trial and error.

Custom Error Page not showing

For some reason, when I get an ASP.NET runtime error, it's not loading my custom error page
<customErrors mode="On" defaultRedirect="app_offline.htm" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="app_offline.htm"/>
<error statusCode="500" redirect="app_offline.htm"/>
</customErrors>
That's in my web.config.
I'm still getting this though and it's not loading my error .htm page:
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
I'm pretty sure that app_offline.htm is a reserved filename in ASP.NET that will always be served if present on the server.
Try renaming it to error.htm and updating your <customErrors /> block to match.
I suspect what's happening is that ASP.NET can't find your custom error page. The path to your error page file needs to be relative or absolute. So either:
<customErrors mode="On" defaultRedirect="~/app_offline.htm" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/app_offline.htm"/>
<error statusCode="500" redirect="~/app_offline.htm"/>
</customErrors>
Or:
<customErrors mode="On" defaultRedirect="http://mysite.com/app_offline.htm" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="http://mysite.com/app_offline.htm"/>
<error statusCode="500" redirect="http://mysite.com/app_offline.htm"/>
</customErrors>
Should solve your problem.
Do you get details of the actual error if you set mode="Off"? If you still get the same default error page, you might find the solution in this post:
CustomErrors mode="Off"
Problem was my site was running under .NET 3.5 when it's a 4.0 app
I also had the same issue. Main problem is related to visibility of your error pages to various users. It is controlled by the tag
Mode
as shown below
I think you have used RemoteOnly . In order to show the custom error page while running in your local machine we have to make the mode value as On. For me it is worked afterwords.
Also we can give error pages for various types of error codes. For example in below figure you can see - I have given redirecting page as CustomErrorAspxPage.aspx for file not found exception type for the status code 404.
At last in order to test this I created exceptions 1)for default exception 2)for 404 file not exists exception as shown in below figure.

How to see errors in an asp.net website?

I just want to see error insteas of asp.net showing me default error Server Error in '/' Application. What should i change in web config?
I used this,
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
Any suggestion i want to see errors in browser as i do live testing...
Change this:
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
To this:
<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
RemoteOnly means you'll see the errors if you're logged onto the web server itself (e.g. http://localhost/) Off means to display the errors to everyone, including remote clients.
An alternative is to browse to your site using it's localhost url. This will allow you to see the errors, but with the customErrors = "RemoteOnly", users browsing to the site using a non-localhost url will see the friendly error page.
Also check the server's eventlog, if you're not confident that you are seeing the full error.

Resources