IIS overriding handling of 404 and 500 http status codes in MVC - asp.net-mvc

I'm using MVC 4 with IIS 7.5. I'm trying to handle 404, 500 and other codes with my own controller and view.
However, no matter what I try, IIS overrides my settings/code and injects it's own 404 (and so on) error pages. This happens locally on dev machine with IIS Express as well as production with IIS 7.5.
Here's a combination of all I've tried so far:
Used tag in web.config with redirect to my custom error view, no luck.
Provided custom error handling in Global.asax. It gets there (tried 404 and 500), it does call my custom controller and view, but at the end, IIS still wins and shows its page instead of my view.
By the way, I'm trying this will extensionless url as well as .html pages. How can I get IIS to leave it alone and allow MVC to take care of these errors.
I"m out of options at this point. Any advice would be appreciated.

You need to override how IIS handles the error status codes. This can be done by simply modifying the <system.webServer> section in your web.config.
<httpErrors existingResponse="PassThrough" />
Full information can be found on the IIS.NET site: http://www.iis.net/configreference/system.webserver/httperrors

Related

MVC customErrors with redirect to subdomain error page

I have project with set of subdomain websites (.NET MVC).
e.g.
admin.example.com
weather.example.com
test.example.com
error.example.com
All this websites have same style and work as one big project, so my idea is to create one place for error pages as subdomain website (error.example.com). I think that in that case I will get one place where I will support my error pages (design, styling and other things).
My question is how to do that using MVC tools and web.config.
P.S.
Also it will be cool to have one place to log exceptions. For now I'm using elmah to log all exception in database.
It is not a usual thing, so I have a workaround.
I used Application_Error of Global.asax to track redirect.

Creating a custom error page for asp.net MVC 3, need to disable http modules

I've a MVC 3 web application using WIF (only thing that matters here is that it's a http module and integrated into the processing pipeline), I've added in normal error handling via global.asax.cs's application_error handler. This works well for most of the cases where the basic application is up and running.
however, there is a class of errors where if the web.config is not configured correctly. (i.e. after a fresh install), the http modules, i.e. WIF assemblies throw exceptions.
I'm trying to put a custom error page for that as well to ask the user to look at the configuration,
however, any page hosted on the same website, even for static html still goes to the standard asp.net error page. My guess is that its still invoking the modules for static pages. Any one have idea on how to disable the httpmodules for certain areas or what the standard practice is?
This is how i'm configuring the custom error page
<customErrors mode="RemoteOnly" defaultRedirect="~/error.htm">
it's a simple static html page. page loads fine when the website is configured properly, but does not show when there is a http module level problem.
You can specify default websites setting in machine.config file. And even protect them from overwrites.
The machine.config file is located in x:\\Microsoft.NET\Framework\\config\machine.config
So if after deployment web.config file will be broken (or some settings) - proper settings will be taken from machine.config.

ASP.NET MVC2: Can't find controller

I have an MVC 2.0 web site that is using Areas. When I go to the default page (localhost/mywebsite/default.aspx), it correctly routes to the correct action in the correct controller and renders the default view correctly.
But on the page I have several Html.ActionLinks, and these do not seem to be able to find the Controller. When I click on the links in the page, I get a 404 error.
The URLs are what I expect: localhost/mywebsite/MyAreaName/Home/Index (for example). I've also tried localhost/mywebsite/Areas/MyAreaName/Home/Index, but this also gives me a 404.
How do I get the Controller to be recognized?
You probably don't have your IIS settings setup correctly to map the requests correctly.
Is IIS verify that you have set the "Wildcard application maps" to:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
And make sure you have the "Verify file exists" checkbox unchecked.
Walkthrough - read section "IIS6 Extension-less URLs"
(source: haacked.com)
More information with IIS 6 MVC setup
More IIS Info
EDIT: Since your using IIS 7, verify that it is running in integrated mode. If it is running in classic mode the mapping is NOT done automatically just like the way IIS6 works.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
You're using areas, have you registered the area routes?
ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404
#Kelsey, I did have the app pool set correctly with integrated pipeline mode. But thanks for leading me down the correct path. I had the required config settings in a web.config in the Area, and not in the root of the web site, so the routing was never applied. I moved the config settings the the root level web.config and everything is working.
Thanks for your help, and Meff, thanks for all your ideas as well.

Custom Errors not Forwarding on ASP.NET MVC Site

On my site, a broken link throws the default, page not found error. In the web.config I have turned on CustomErrors and forward 404 errors to a custom message.
On my dev box it works, on the host it does not.
Any ideas? ASP.NET MVC 1.0, SQL 2005, IIS 6 host (ya, I wish it was IIS7 - but they want to charge me to move the site).
Thanks in advance!
CustomErrors will only fire for files which .NET is actually assigned to handle. On your local Visual Studio this covers everything, but in IIS6 it only covers the files that are actually directly related to .NET (.aspx, .ashx, .asmx etc). This means that if you want it for everything you have to add an ISAPI filter to bind all files to be handled by .NET, which comes with overheads and can cause some unexpected behavior if you have any global handlers or HttpModules defined.
This page will help you with configuring a wildcard binding if that's the road you want to go down
Have you considered putting it in the IIS6 configuration instead of .NET? This may be simpler for you than trying to use the CustomErrors from .NET in IIS6.
As a sidenote IIS7 integrated pipeline mode does not have these issues and all files are handled by .NET by default.
It is possible a machine.conf setting is overwriting your web.config setting.
Have you contacted your host and asked them if they overwrite the CustomErrors tag?

Internal Server Error due to config lockdown when deploying my ASP.NET MVC app to my web host

I'm developing an ASP.NET MVC website on a local Windows Server 2008/IIS7 machine and am I'm now attempting to deploy it to my web host provider, ASPnix. I'm using their Shared Web Hosting service and have been placed on an IIS7 server which they claim supports ASP.NET MVC.
However, when I deploy the application up to their servers, I get an "Internal Server Error".
Here's the Error Summary:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Here are the relevant portions of the Detailed Error Information:
Module: IIS Web Core
Notification: BeginRequest
Handler: Not yet determined
Error Code: 0x80070021
Config Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
And the Config Source looks like this:
144: </modules>
145: <handlers>
146: <remove name="WebServiceHandlerFactory-Integrated"/>
The error is coming from the fact that I have a system.webServer section in my web.config file that has a handlers child section. The system.webServer section is the exact config section that was laid down by default when I first created the ASP.NET MVC website in Visual Studio. It has the following XML comment above it:
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
I take the handlers child section out, and the 500 error goes away. Of course, that section is required for an ASP.NET MVC application to work properly in IIS7, so simply taking it only produces other errors (404 errors in this case since routing doesn't work).
The support engineers at ASPnix claim that ASP.NET MVC is installed and configured properly in IIS7 on their servers. I'm not saying I don't believe them as this is the first ASP.NET MVC site that I've built and deployed. However, I can't think of anything I could do to make this work since it appears to be a config issue at a level that I don't have access to.
This issue smells like it would be a common issue with folks trying to deploy ASP.NET MVC to a hosting provider. Has anything run into this either with ASPnix or other web hosting companies and hopefully found a solution?
ps
One odd thing. When researching this issue on the web I find many people saying they had to set the overrideModeDefault attribute their applicationHost.config files of IIS7 to from "Deny" to "Allow". However, my local development server has this set to "Deny" and everything works fine. Even so, I don't have access to the applicationHost.config file anyway on the web host's server.
Open IIS Management, Under the main server node, select open Feature Delegation (in Management section)
"Handler Mappings" to "Read/Write" instead of "Read Only"
It looks like your hosting provider unnecessarily locked down IIS.
I was able to recreate the problem on my local IIS 7.5 server.
See this for a global settings reset.
please check if you deployed your application properly : Deploying an ASP.NET Server (IIS 7)
The link to
http://www.winservermart.com/Howto/HTTP_Error_500_19_IIS_7.aspx
doesn't fix the problem. The "reset delegation" creates an exception in web.config for a particular domain only which makes the site work, but doesn't answer how to set it permanently system wide.
So, it's not shame, because we know the solution and set all settings correctly. And advertising here some other hosts pointless we have tons of clients that are running from wh4l and describing how great their overloaded servers.
-Polk

Resources