404.html, ASP.NET MVC root directory - asp.net

I have found couple of solutions for error pages in MVC. Most of the solutions are based on Routes and a separate Error controller. But I need a most simple html based error pages, with no preprocessing at all.
Is there a way to serve 404.html, 403.html and 500.html files bypassing the routes file, as static content?
I have placed those three html files in my ~/Views/Shared/ and the following in web.config, the one at application root:
<system.web>
<customErrors mode="Off" />
<error redirect="~/500.html" statusCode="500" />
<error redirect="~/404.html" statusCode="404" />
<error redirect="~/403.html" statusCode="403" />
</customErrors>
</system.web>
But it throws error at third line of the above XML locally and from remote it throws 500 internal error with a default IIS theme.
Which directory is considered root for serving static HTML files?

CustomErrors mode should be "On" or "RemoteOnly", and the CustomErrors tag should not be closed - as #Preyash Desia stated
<customErrors mode="On">

<system.web>
<customErrors mode="Off">
<error redirect="~/500.html" statusCode="500" />
<error redirect="~/404.html" statusCode="404" />
<error redirect="~/403.html" statusCode="403" />
</customErrors>
</system.web>
You have got extra "/" at the end of line 2, its invalid xml; remove it.

Related

I am using UrlRewritingNet.UrlRewrite dll, how to redirect to Error page when bad request get fired?

Currently I am using UrlRewritingNet.UrlRewrite dll for URL rewriting in Asp.Net #3.5.
Without using any special character it works fine ex. URL1.
But after giving special characters in URL it throws Bad Request error ex. URL2
URL1: http://www.example.com/search/0253
URL2: http://www.example.com/search/0253:0253
To handle this error, I want to redirect it to some other Error Page, How can I do this?
On IIS 7+ you can define error pages for all statuses, for 400 Bad Request :
<httpErrors>
<error statusCode="400" path="/bad-request.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL"/>
</httpErrors>
or trough IIS console go to the error pages and add custom error page for status code 400 :
The best way is by using Web.config file like
<system.web>
<!-- other system.web stuff -->
<customErrors defaultRedirect="/Error404.aspx" mode="On" redirectMode="ResponseRewrite">
<error redirect="/Error404.aspx" statusCode="404" />
</customErrors>
</system.web>
<system.webServer>
<!-- other system.webServer stuff -->
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
For more details click here

Asp.net web.config Handle Error page "File or directory not found"

I have page i.e. Default.aspx. I can handle error pages like 404,403. But when I change the extention of page then server give me an error.If I change Default.aspx to Default.asasd. Here I have just changed the extention of page then server gives following error
I added 404 error page in my web.config file. How can I solve this?
Web.config
<customErrors mode="On" defaultRedirect="~/ErrorPages/DefaultErrorPage.aspx" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="~/ErrorPages/404.aspx" />
<error statusCode="403" redirect="~/ErrorPages/403.aspx" />
</customErrors>
Add this:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/Error.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>

Redirection not working

I have an asp.net application running on integrated pipeline and I have this specified in the web.config:
<customErrors mode="On">
<error statusCode="404" redirect="404Error.aspx" />
</customErrors>
However, my site still shows the generic 404 asp.net error.
Why is this?
this will work for you
<customErrors mode="On">
<error statusCode="404" redirect="http://www.easycomputerformat.com/404error.aspx" />
</customErrors>
try following too...
<error statusCode="404" redirect="~/404Error.aspx"/>
sample :
<configuration>
<system.web>
<customErrors defaultRedirect="http://www.easycomputerformat.com/GenericError.htm"
mode="On">
<error statusCode="404" redirect="http://www.easycomputerformat.com/404error.aspx"/>
<error statusCode="403" redirect="http://www.easycomputerformat.com/403error.aspx"/>
</customErrors>
</system.web>
</configuration>
Are you sure the 404Error.aspx file exist in the root of the application ?
redirect non aspx pages to error page
you can set custom error page for IIS by setting 404 error page for your virtual directory

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