IIS 7 Error Page for file with asp Extension - asp.net

I have tried many ways but unable to do this. I have set the web.config as below.
<?xml version="1.0"?>
<configuration>
<system.webServer>
<asp scriptErrorSentToBrowser="true"/>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On" defaultRedirect="index.asp">
</customErrors>
<compilation debug="false"/>
</system.web>
</configuration>
When I try this url
http://www.aboutmanchester.co.uk/wddwd.asp
It show a message not the error page I mention but when I try
http://www.aboutmanchester.co.uk/wddwd.aspx
I goes to the custom error page.

Is the application pool set to 'classic'?
http://technet.microsoft.com/en-us/library/cc753449%28WS.10%29.aspx

Is that an exact web.config copy? Without the errorMode="Custom" attribute on the httpErrors element I only get 404 pages to work with .aspx pages and get a generic IIS error page if I hit a issing .asp page. Adding the attribute gives me the expected behaviour.
<httpErrors errorMode="Custom">

Related

ASP.NET 404 Redirect triggered even for missing CSS/JS Resource Files

I setup a 404 redirect if a visitor lands on a missing or non-existing ASPX page. However, it's now triggering for missing CSS/JS Resource files as well.
Web.config:
<configuration>
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="404.aspx" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
But in my signin.aspx page, I've got some missing resources (non-critical and I'm planning on removing them), however because of the Resource 404, the app now redirects the visitor to the 404 page, which is not what I intended.
How can I fix this?

IIS custom errors not showing custom error page

I have custom error pages setup on an ASP.NET website.
There is one error that is not showing a custom error page, and just showing the usual yellow ASP.NET error page. If custom errors are turned on it shows "Server error in / application" / "Runtime error", but if custom errors are off it shows "validation of viewstate mac failed" error.
The relevant parts of my web.config are:
<system.web>
<compilation debug="false" targetFramework="4.0" />
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="/404.aspx" />
<error statusCode="500" redirect="/500.aspx" />
</customErrors>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" />
To trap for this error do I have to use a different status code or substatuscode or is there something else?
NB. Server 2008 R2, IIS 7.
After further research I see that this means that IIS is displaying the error rather than ASP.NET.
I changed the system.webServer part of my web.config so IIS can also use the custom error page and that has solved the problem.
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/500.aspx" />
</httpErrors>

Asp.net custom 404 not working using Intelligencia rewriter

Web.config :
<customErrors mode="On">
<error statusCode="404" redirect="~/Page-Introuvable" />
</customErrors>
Rewriter.config :
<rewriter>
<rewrite url="~/Page-Introuvable" to="~/PageNotFound.aspx" />
</rewriter>
When typing this unexisting url :
http://example.com/qwerty.aspx
I get to see my error 404 custom page
When typing this :
http://example.com/qwerty (without .aspx)
I get server page 404 error
I'd like to know how to display my custom page in this case.
Thank you very much!
ANSWER
Added this to web.config section System.webServer :
<httpErrors errorMode="Custom">
<clear/>
<error statusCode="404" responseMode="Redirect" path="PageNotFound.aspx"/>
</httpErrors>
<customErrors> are just for extensions handled by asp.net (aspx, ashx...), for all others use <httpErrors>: http://www.iis.net/ConfigReference/system.webServer/httpErrors
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="ExecuteURL" defaultPath="/error.aspx?code=404">
<clear/>
<error statusCode="404" responseMode="ExecuteURL" path="/error.aspx?code=404"/>
</httpErrors>
</system.webServer>

ASP.Net Swallowing 404 Error

So I've set up a rule in IIS7 to redirect to a specific page on a 404 error.
This works great as long as I'm typing URLs such as:
www.abc.com/Test/
However as soon as I attempt to access a file that doesn't exist
www.abc.com/Test/Test.aspx
I get the ASP.Net error message:
Server Error in '/' Application.
The resource cannot be found.
How can I keep ASP.Net from swallowing the 404 error and overriding my settings in IIS7?
EDIT: Here's my web.config file. IIS added the system.webServer stuff not me.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<httpErrors>
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/redir.aspx" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/redir.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
If you're in Classic pipeline mode, you may be able to use the "Invoke handler only if request is mapped to file" option. I had to turn it on for two .aspx mappings--I think one was 32 bit and one was 64.

Implementing a Custom Error page on an ASP.Net website

I have an ASP.Net website and I want to use a custom error page. I put the following code in my web.config
<customErrors mode="On" defaultRedirect="~/error.aspx">
<error statusCode="404" redirect="~/error.aspx" />
</customErrors>
The problem is when i go to a URL that does not exist is still uses the 404 error page specified in IIS Manager.
Question: How can I make it use the error.aspx page I have created? Why do the settings in IIS Manager override the web.config?
Try this way, almost same.. but that's what I did, and working.
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="apperror.aspx">
<error statusCode="404" redirect="404.aspx" />
<error statusCode="500" redirect="500.aspx" />
</customErrors>
</system.web>
</configuration>
or try to change the 404 error page from IIS settings, if required urgently.
There are 2 ways to configure custom error pages for ASP.NET sites:
Internet Information Services (IIS) Manager (the GUI)
web.config file
This article explains how to do each:
How To Set Up Custom Error Pages In IIS 7.5 With ASP.NET
The reason your error.aspx page is not displaying might be because you have an error in your web.config. Try this instead:
<configuration>
<system.web>
<customErrors defaultRedirect="error.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="error.aspx"/>
</customErrors>
</system.web>
</configuration>
You might need to make sure that Error Pages in IIS Manager - Feature Delegation is set to Read/Write:
Also, this answer may help you configure the web.config file:
What is the difference between customErrors and httpErrors?
<customErrors defaultRedirect="~/404.aspx" mode="On">
<error statusCode="404" redirect="~/404.aspx"/>
</customErrors>
Code above is only for "Page Not Found Error-404" if file extension is known(.html,.aspx etc)
Beside it you also have set Customer Errors for extension not known or not correct as
.aspwx or .vivaldo. You have to add httperrors settings in web.config
<httpErrors errorMode="Custom">
<error statusCode="404" prefixLanguageFilePath="" path="/404.aspx" responseMode="Redirect" />
</httpErrors>
<modules runAllManagedModulesForAllRequests="true"/>
it must be inside the <system.webServer> </system.webServer>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="your page" responseMode="Redirect" />
</httpErrors>
</system.webServer>
Is it a spelling error in your closing tag ie:
</CustomErrors> instead of </CustomError>?

Resources