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.
Related
I have been trying to configure Custom Error pages in ASP.NET MVC 5 but with little complete success.
To do this, I have followed this guide: http://benfoster.io/blog/aspnet-mvc-custom-error-pages
Web.config customerrors
<customErrors mode="On" defaultRedirect="~/500.aspx" redirectMode="ResponseRewrite">
<error statusCode="401" redirect="~/401.aspx" />
<error statusCode="403" redirect="~/401.aspx" />
<error statusCode="404" redirect="~/404.aspx" />
</customErrors>
Web.config httpErrors
<httpErrors errorMode="Custom" >
<remove statusCode="401" />
<error statusCode="401" path="401.html" responseMode="File" />
<remove statusCode="403" />
<error statusCode="403" path="401.html" responseMode="File" />
<remove statusCode="404" />
<error statusCode="404" path="404.html" responseMode="File"/>
<remove statusCode="500" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
I have removed the HandleErrorAttribute from filter config.
With this setup, I get the following results:
Browse to a non-existent static resource
Example: http://my.website.com/fakeresource.htm
This results in the static 404.htm file configured in the httpErrors section.
The Url is preserved in the browser address bar
A 404 status code is correctly set.
Browse to a bad route
Example: http://my.website/realcontroller/fakeaction
This results in a HttpException being thrown when a matching route cannot be found.
The 404.aspx page is displayed.
The Url is preserved in the browser address bar.
A 404 status code is correctly set.
Browse to a valid route, but with an invalid ID for a database resource
Example: http://my.website.com/realcontroller/realaction/22
(22 is the ID of a resource which does not exist, the Action will return the HttpNotFound() method.
This results in the static 404.htm file configured in the httpErrors section.
The Url is preserved in the browser address bar
A 404 status code is correctly set.
If I throw HttpException(404, "Not Found") instead of using HttpNotFound(), I get the 404 defined in customErrors
Exceptions & Unauthorised Requests
Also all work correctly using this configuration of Web.config
However, any action which checks ModelState with ModelSate.IsValid, or adds errors using ModelState.AddModelError("InputName", "Error Message"); results in a 400 Bad request.
Here are the errors I get in IE & Chrome:
IE
Chrome
Instead, what I should be getting is the original view, with the validation messages displayed next to the inputs which failed validation.
If I remove the httpErrors section from web.config, the issue is resolved, but I no longer get custom IIS error pages.
I have also tried every option of the existingResponse property on httpErrors but different options breaks either the error pages or the ModelState validation.
Finally I tried setting Response.TrySkipIisCustomErrors = true; and this appear to fix the problem in the action I was testing.
But this means that I have to set this property on every action which uses ModelState, and that just doesn't sound right.
What am I doing wrong?
UPDATE
To test if this was project specific, I created a new project in VS2012 and configured the same error pages. Frustratingly, everything worked. The only difference I can think of now is that the project experiencing the problem originally started out using MVC 4, and was upgraded to MVC 5.
It would appear that custom errors had nothing to do with the bad request I encountered.
Instead, there was another form on the page which was incorrectly also being called when the main form was being posted.
I am trying to use in a asp.net webforms application custom error pages so i am doing something like this (example the 404 error) :
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<clear />
<error statusCode="404" path="/Pages/Errors/Error404.aspx" responseMode="ExecuteURL" />
</httpErrors>
now for the problem, it seems to work half-way, meaning that when a not found page error occurs it is trying to redirect to my Error404.aspx page but resulting in another 404 error because it can't find my custom page . This is INCEPTION!!
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Pages/Errors/Error404.aspx
i checked and rechecked my path ,Pages and Errors folders exists, Error404.aspx exists, if i write the path in browser i can access the page , so indeed exists,
so what is the problem?
Try to add the ~ in the path:
<error statusCode="404" path="~/Pages/Errors/Error404.aspx" responseMode="ExecuteURL" />
another solution is using redirect:
<error statusCode="404" redirect="~/Pages/Errors/Error404.aspx" />
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.
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.
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>