I'm having a really wierd error with Custom errors setting on IIS 7. I have an ASP.NET MVC3 application which uses JavaScript/Ajax/Jquery.
I am trying to move my hosting over to another provider and am testing to ensure everything works fine. When the custom errors setting is 'OFF' everything works fine.
However setting it to 'ON' with a redirect is causing the JavaScript that is in the View to be displayed at the top of the screen! This is my custom errors setting below:
<customErrors mode="On" defaultRedirect="/Errors/Error/Index">
<error statusCode="404" redirect="/Errors/Error/Error404"></error>
</customErrors>
For what it's worth, I've got exactly the same settings on my current provider and it works perfectly fine! So I'm at a loss to understand what's happening. Unfortunately my hosting provider doesn't seem to understand the issue either. Please can somebody help?
EDIT: When I remove the defaultRedirect attribute and the error element, it works fine. It just doesn't seem to like the attribute or element.
Thank You,
Related
I have my web.config setup as follows:
<customErrors mode="RemoteOnly" redirectMode="ResponseRedirect" defaultRedirect="~/SpecialPages/PageNotFound.aspx">
<error statusCode="404" redirect="~/SpecialPages/PageNotFound.aspx" responseMode="Redirect"/>
</customErrors>
But when a user goes to mysite.com/gibberish, my 404 page shows up, but the url stays as mysite.com/gibberish, but I want it to say mysite.com/SpecialPages/PageNotFound. Is there somethng else I am missing?
I'm using Kentico10 CMS if that makes any difference but have been following their instructions too. Seems like I'm missing something server side.
Have you specified Page not found in Kentico? If so, remove that configuration beacuse you don't want Kentico to handle error for you and then your custom errors in web.config should work as you set them up as in any other project.
In case anybody is reading I got an answer from kentico themselves:
This behavior is correct from SEO point of view. Previously we had the
behavior you wanted but it was really bad for SEO to do a redirection
so it was changed and just the 404 status code is returned and the URL
is the same. If you want to change this behavior, you can create
custom event handler and in the request end event check the status
code and if it is 404, do a redirection - but this can harm your SEO
rankings.
https://docs.kentico.com/k11/custom-development/handling-global-events/reference-global-system-events#Reference-Globalsystemevents-RequestEvents
I have a controller where an action returns a 404 error on ASP.NET MVC. Working locally, I get the page with 404 error correctly. When I deploy it to azure, instead of the page, I only get a text-only page:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I've tried all three values on on customErrors mode in web.config (mode = Off, On, RemoteOnly) and it doesn't seem to change anything at all.
Why is Azure behaving differently on 404 errors and how can I make it behave the same as local IIS?
Okay I've found out the problem. Apparently, it wasn't even hitting the ASP.NET's custom errors handler, and was being caught at server level.
I've played with web.config and added this:
<httpErrors errorMode="Detailed">
<remove statusCode="500"/>
</httpErrors>
It now passes my error to the ASP.NET's custom error handler correctly.
I've created a custom error page, using this article. This custom error page appears only when aspx page isn't find, and when file(like pdf and other) isn't find - default google's error page appears. How to get custom error page for files? I've tryed to implement this solution on two different machines: on local machine custom error page appears for both .aspx pages and files, but on a server this solution works only for .aspx pages, though config files are the same. What I'm missing? Maybe there are different IIS configuration on this machines, or something? Thanks in advance.
I think this will help you.
<system.web>
<customErrors defaultRedirect="Error.aspx" mode="On">
<error statusCode="500" redirect="Error.aspx"/>
</customErrors>
</system.web>
U can add additional tags and mention available error codes and the page where you want to redirect.
Try setting your Error Page directly in IIS. Take a snapshot of your Web.config before you do this as I'm pretty sure it's going to be modified by IIS once you make this settings change. If memory serves me right you'll see this change in system.webServer and not system.web.
Be advised, if you are operating in a web far though, using mixed version of IIS (Server 2008 and Server 2008 R2 for instance), I've found the settings for 2008 R2 to not be compatible with 2008.
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 toggled customErrors=On in web.config, set the defaultRedirect for my custom Error.aspx page. However, this is only to prevent application errors from spitting out code - I'd still like IIS to handle 404s etc. with its default handlers, since they work fine.
Any way to specify in my ASP.NET app or IIS for IIS to take priority?
I know I could add the formatting in my Error page...but I'd just be replicating what exists in IIS.
It didn't tried it (I don't have visual studio on that box) but maybe if you set your customErrors to handle only error 500 (server error), that'll work. Just a guess.
Let me know if it works
You can do it in the web.config file
<customErrors = "On">
<error statusCode = "404" redirect = "route_name"/>
</customErrors>
Don't forget to register the route in the Global.asax.cs