My setup:
Windows 7 Ultimate
IIS 7
Visual Studio 2008
The scenario:
building a simple website locally
an exception is occurring in my app (this is perfect, since I'm trying to setup a custom error page)
without customErrors setup in the web.config file, I get detailed info about the error
WITH customErrors setup in the web.config file, I get the following page when my error occurs:
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.
There's more text than that, but I'm sure you've all seen it before. At this point, the URL is:
http://localhost/bluheron/Error.aspx?aspxerrorpath=/bluheron
So, it looks like it redirected to my error page (Error.aspx), but I'm not seeing my error text ("An error has occurred. Plese try again."). Instead, I'm getting a funky URL with loads of other text, including instructions on how to setup my web.config file, which, by the way, contains this:
<customErrors mode="On" defaultRedirect="Error.aspx" />
It's in the default location, which is inside the system.web section, which is inside configuation section.
By the way, my Error.aspx page is in the root of my app.
Can someone explain what the fancy URL is all about and why my simple error page isn't displaying?
Thanks,
Jay
The error redirect is just what happens normally with customErrors...you can however disable this behavior and preserve the original url (not sending a 302 redirecting your user to the error page's url). This will execute/send the output of your error page:
Add redirectMode="ResponseRewrite" to your customErrors declaration:
<customErrors mode="On" defaultRedirect="Error.aspx" redirectMode="ResponseRewrite" />
If you're still getting the same behavior, there's something wrong with the whole application, and you should turn customErrors off and see what the issue is (this happens with an invalid web.config and many other cases).
Related
I keep getting this when I try hit the link of a website I just deployed to the web host's server:
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.
It Suggests I set the following in my web.config file so I can see details of the error:
The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.
So I have added the following to my webconfig file and created a mycustompage.htm relative to the web.config file:
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
My mycustompage.htm is empty, is there anything I should add in there? When I try hit the link now all I get is a blank page after the server tries to redirect to mycustompage.htm.
Depending on what you're trying to accomplish:
1) You want to view the actual error information.
In this case, remove the defaultRedirect attribute and change mode to Off. Custom errors intercept the standard Yellow Screen of Death (YSOD) ASP.NET error page. By setting Custom errors to Off, the YSOD error message will be visible to both local and remote clients (all remote users will see the error details).
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
2) You want to build a custom error page to handle how your application responds to error conditions.
In this case, you might edit the mycustompage.htm to display a friendly "An error has occurred" message rather than seeing the default Custom Errors are not enabled message.
Link here for reference.
We have custom error page for a webservice. The custom error page is displayed properly in test environment. The same fails in production environment, a 'Runtime Error' page displays showing how to setup CustomErrors.
I have the following pieace of code in Web.config:
<customErrors mode="RemoteOnly" defaultRedirect="WebServiceError.aspx"/>
I have the following code in webserviceerror.aspx
Response.ContentType = "text/xml";
Response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>");
Response.Write("<WebServiceError>");
Response.Write("<ErrorCode>9999</ErrorCode>");
Response.Write("<ErrorDescription>Errore Tecnico</ErrorDescription>");
Response.Write("</WebServiceError>");
1) i am able to open WebServiceError.aspx without any issues from browser.
2) i have tried with a html file WebServiceError.html , this also fails
3)i have tried mentioning absoulte and relative paths for refering webserviceerror.aspx in web.config
4) I have checked that the web.config file is proper and not having any issues.
I have been not able to find the solution for long time now, Please Help.
Thanks in advance,
Pradeep
A few points that come to mind:
You should always include the path to your error page in the <customErrors> tag.
<customErrors mode="RemoteOnly" defaultRedirect="/myErrorPageFolder/WebServiceError.aspx">
The mode="RemoteOnly" attribute tells IIS that you only want to see the custom error pages when requesting the page from a machine other than the one that is hosting the site. If you're running the browser and web server on the same box (typical when debugging using the VS web server or a local IIS instance), you won't see your custom error page.
If there are any errors in your webServiceError.aspx, it won't work correctly.
How are you calling the web service? Have you tried looking at the request and response in Fiddler?
I deployed an asp.net website to a shared server.....
I got the error
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.
Here is my page http://static3.nextgenits.com/Forms/Homepage.aspx
What am i missing ?... Any suggestion...
Your application's web.config is not configured to show the error messages remotely. You will have to edit your web.config and un-comment the customErrors section. Also make sure you set it to RemoteOnly . Once you do this you will see the actual error on the screen and then you can correct it accordingly. Here is the web.config section to be used:
<customErrors mode="RemoteOnly"/>
Set it to debug="true" and you will see the error. Or browse it from the local machine if thats possible. I would also recommend you use something like elmah to log errors in your application. Then you will always be able to see the error when you have your custom error pages set.
The reason you get the message is because you have some other error that asp.net doesn't want to display in release mode as it might contain sensitive information that you don't want the end use to see.
Maybe a typo in your web.config preventing asp.net to eval. customErrors section.
EDIT:
Bit more clear. If there is an error in the web.config (it's an XML File) then ASP.NET isn't able to parse that file. This is an error. As asp.net can't parse the web.config it ignores any settings.
I've got this in my web.config and it's being hosted by the DiscountASP.net ISP
<customErrors mode="On" defaultRedirect="">
<error statusCode="404" redirect="404.aspx"/>
<error statusCode="500" redirect="404.aspx"/>
</customErrors>
I am hosting the site on DiscountASP.net and they also tell you to config it this way. I'm using Enterprise Library but I don't think that should make a difference. I don't believe I need to config anythign for a 404 in EL.
When my page loads with an error, my 404.aspx doesn't show and I get the default custom errors off message. I do not know why I don't get my 404.aspx page showing and get this instead:
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 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".
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 configuration tag to point to a custom error page URL.
Have you tried using a relative path to see if that makes a difference?
<error statusCode="404" redirect="~/404.aspx"/>
Alternately, try an absolute path:
<error statusCode="404" redirect="http://www.domain.com/errors/404.aspx"/>
EDIT: As others have pointed out, and based on your comment to another answer, the 404 error page should be displayed when someone navigates to a page that doesn't exist, whereas general errors on a page could be captured by the defaultRedirect. So if you're testing the 404 then make sure you're testing with a nonexistent page. To test the defaultRedirect then have one of your pages throw an exception etc.
Is it possible that you are overriding this in another web.config, say in a sub folder? Or we can go the other way. Are you sure this is in the application root?
Is there any reason why you don't want to use the defaultRedirect for 500 errors?
You are FTP-ing the files correct? Try uploading the file as a binary file instead of text. You might be suffering from an encoding problem. I'm willing to bet right now that nothing you are doing in your web.config is working.
I found a solution here.
The real catch was using this:
Response.TrySkipIisCustomErrors = true;
I'm working on IIS6, ASP.NET, VS2008. The web site uses a custom error handler to catch 404 errors and serve an alternate page. When presented with an url of the form:
http://srv/crimson/articles/index
Everything works perfectly. But an url of the form:
http://srv/crimson/blog.aspx
Where blog.aspx does not exist, fails with the following message:
Server Error in '/Crimson' Application. Description: HTTP 404...
When I try and debug, none of the breakpoints in my 404 handler are hit. So it appears that something is catching the request earlier. Where? And how to I get it to pass the request on to my handler?
Edit
Thanks to those who answered, but none of those ideas worked. I've decided to attack the problem another way.
You might wanna try this:
In IIS6:
open "properties" for your website
go to "home directory" tab
click on "configuration"
look for the extension ".aspx"
click on "edit"
check the checkbox which says "verify that file exists"
edit
And what about this:
http://msdn.microsoft.com/en-us/library/h0hfz6fc(VS.80).aspx
<customErrors defaultRedirect="sorry.htm" mode="On">
<error statusCode="404" redirect="NotFound.aspx"/>
</customErrors>
Since 'RemoteOnly' specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host.
hmm, Assaf is right, but to add to his answer I need to post some code.
Yes, Assaf does mean something else ASP.NET offers it's own error handling, configured through the web.config. You can either manage this through the IIS Admin snap in, or directly in the web.config file.
Within the <system.web> element you should have:
<customErrors defaultRedirect="sorry.htm" mode="RemoteOnly">
<error statusCode="404" redirect="NotFound.aspx"/>
</customErrors>
You can configure a different page for each HTTP error code, or let the default redirect handle them all.
You'll find that you do indeed need to set these error pages up in both the IIS custom errors and the ASP.NET configuration, as otherwise you'll end up in this situation - some pages go to your 404, and others use a default that you've not customised.
You should also make sure that your custom 404 page actually returns a 404 header to ensure that search engines etc treat it correctly.
Response.StatusCode = 404;
Response.StatusDescription = "Not found";
ASP.Net has a custom errors configuraiton of its own.
Go to the ASP.Net configuration of your virtual directory (web application) and right-click -> ASP.Net -> Edit Configuration -> Custom Errors.
Maybe you got a 500 so redirect for 404 is not triggered. You may focus on this 500 error at first.