How to see errors in an asp.net website? - asp.net

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.

Related

.NET Compilation Error, show user friendly screen

I've configured the web.config to show user friendly 404 and 500 errors using the following declaration:
<customErrors mode="Off" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="error.aspx"/>
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
However occasionally when we're FTP'ing classes up to the server (in the App_Code folder) we may cause a compilation error that doesn't get handled gracefully and the user sees the yellow screen of death. Is there a way to hide this and show a standard holding page instead? Perhaps some adaptation of the web.config declaration above?
I know ideally we should be compiling first and publishing but we are doing a lot of dynamic changes at the moment, that make this difficult.
You can modify web.config in following way to show user-friendly messages on any error:
<customErrors mode="on" defaultRedirect="otherError.aspx" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="error.aspx"/>
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
Edit:
If you don't want to see compilation errors while updating your website, you can take it offline for the time of the update.
To do that, put a file named app_offline.htm in the root of your website.
The content of that file should state, that website is under maintenance/update. You can adapt content that it will be in the same style as your website.
When you are done with the updates, simply rename that file and website will work as supposed to.

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.

ASP.NET Web.config debugging

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.

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.

Why are custom error pages not working for 404 errors

I have set up a page to handle errors that occur in a website I work on using web.config. I have used the customErrors section in web.config to do this, as described here
Here is the relevant section
<customErrors mode="On" defaultRedirect="page.aspx?IDDataTreeMenu=357">
<error statusCode="403" redirect="page.aspx?IDDataTreeMenu=357"/>
<error statusCode="404" redirect="page.aspx?IDDataTreeMenu=357" />
</customErrors>
This seems to work for all errors except 404. I just get the standard IIS 404 error when accessing a URL that doesn't exist.
What am I missing here?
This site is hosted on a shared server, so changing settings in IIS is not an option
Check with the ISP and see if they have a place where you can insert a reference to your own custom 404 page.
At Network Solutions they give you a control panel and a page where you can set this up.
<httpErrors>
<clear />
<error statusCode="404" subStatusCode="-1" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>

Resources