not found error not handling in web.config - asp.net

i am trying to put customError tag in web.config file..
still it doesn't redirect to default url
http://www.lacopainn.com/page/2/?p=dbasndwefxknyafc&wpmp_switcher=mobile
here is my site. when we enter this url it shows error of
Not Found
The requested document was not found on this server.
how can i handle this error and redirect to detault page??
please help

you need to put following tag under System.web tag in your webconfig file
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="default.aspx" />
</customErrors>
</system.web>
Hope it will fix your problem.

Related

invalid or unknown .aspx pages do not trigger 404, and instead display marker file text

On my web server, if i visit a page that does not exist, it generates a proper 404, UNLESS that page ends in .aspx. If the invalid url ends with .aspx, IIS generates the marker file error:
"This is a marker file generated by the precompilation tool, and should not be deleted!"
instead of a proper 404. How can i make IIS display/serve a 404 for unknown or invalid .aspx pages?
For example:
http://www.mysite.com/iDontExist.txt --> generates proper 404
http://www.mysite.com/iDontExist.aspx --> marker file error instead of 404
any ideas?
You need to turn on the custome errors via the web.config
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.html" mode="On">
<error statusCode="404" redirect="PageNotFound.html"/>
</customErrors>
</system.web>
</configuration>
More information on this can be found in MSDN
The trick was to set the "redirect mode" of the customErrors tag to 'ResponseRedirect' instead of 'ResponseRewrite':
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="customError.aspx" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="customError404.aspx" />
<error statusCode="500" redirect="customError500.aspx" />
</customErrors>
</system.web>

asp.net customErrors does not react

I need help with settings. It's never use provided page for error 404.
This is my customErrors web.config block:
<customErrors mode="On" defaultRedirect="/systemerror.aspx">
<error statusCode="404" redirect="/404.aspx" />
</customErrors>
I have these page created and they works well if I call them by url, but when I write in url non-existent page like:http://www.mysite.com/asdfasdasd I am getting:
Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
It's not use my custom error page 404.aspx, how can I fix this ?
If you are using IIS 7, try:
Response.TrySkipIisCustomErrors = true;
Refer:
HttpResponse.TrySkipIisCustomErrors Property :Gets or sets a value that specifies whether IIS 7.0 custom errors are disabled.
You are missing ~
<customErrors mode="On" defaultRedirect="~/systemerror.aspx">
<error statusCode="404" redirect="~/404.aspx" />
</customErrors>
This should work. Let me know.

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.

ASP.Net partially ignoring my Custom error section in web.config

Here's my web.config customErrors section (you'll notice I've switched the mode to 'On' so I can see the redirect on my localhost):
<customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On" redirectMode="ResponseRewrite">
<error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
</customErrors>
and here's the code that throws:
Catch adEx As AccessDeniedException
Throw New HttpException(DirectCast(HttpStatusCode.Forbidden, Integer), adEx.Message)
End Try
and here's what I end up with:
Which is not my pretty AccessDenied.aspx page but it is a forbidden error page so at least I know my throw is working.
I've removed the entry for 403 in IIS (7.0) as a desperate last attempt and unsuprisingly that made no difference.
I've run out of ideas now so any suggestions will be gratefully appreciated!
In fact, your aspx page may not be executing at all.
Go to IIS.
Go to your default website properties.
Click on the Home Directory Tab
Click the configuration button.
Now, check if a .aspx page is registered there.
You need to specify existingResponse="PassThrough" in the system.webServer section of the httpErrors element.
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>

Custom error handling for a specific page in ASP.Net

On a site I run, I have 404's and 500 errors mapped to redirect to a custom error page for end users; using the following code in my web.config:
...
...
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
...
...
However, I have one specific page that I do not want redirected; a health check page to make sure the site is 100% operational. I tried setting a location specific custom error handler using the code below in my web.config:
...
...
</system.web>
<location path="health.aspx">
<system.web>
<customErrors defaultRedirect="" mode="RemoteOnly"></customErrors>
</system.web>
</location>
...
...
However, it doesn't seem to work. When I rename health.aspx to something else like badhealth.aspx, then make a request, I expect to get a generic 404 error via the Yellow Screen of Death page. Similarly, by intentionally changing the code to throw an error, I should get 500 error via the YSOD page. In both cases, I end up being redirected to our custom 404 page, rathen then getting a YSOD. Thoughts?
Any assistance is greatly appreciated.
Thanks all,
- Frank
Nevermind, we solved the issue. It seems when you have a location specific customError directive; if you leave the defaultRedirect as "", it will default to the sitewide defaultRedirect URL.
The solution was simply to turn off CustomError handling for this specific path, like so:
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
</system.web>
<location path="health.aspx">
<system.web>
<customErrors mode="Off"/>
</system.web>
</location>
Thanks anyway, Jose.

Resources