ASP.NET MVC 4 catch-all only runs on local, not remote requests

In the ASP.NET MVC 4 application, we set up the entire route for tracking:

routes.MapRoute( name: "UnKnown", url: "{*url}", defaults: new { controller = "CatchAll", action = "UnknownUrl" }); 

The UnknownUrl method in CatchAllController correctly loads its view into our development environment.

However, in IIS 7.5, a standard 404 page is displayed if a non-existent remote request arrives . a local request sent using RDP on the server itself works fine .

In web.config, tp is installed

 <customErrors mode="Off"/> 

What is the difference between a local call and a remote call? How can we get the MVC HttpHandler to catch these requests?

A hint might be that we were also unable to get IIS to show detailed 500 status messages when called remotely.

+4
source share
2 answers

I am having problems with IIS showing default errors instead of .NET errors, which I fixed using the following in system.webServer in the web.config file:

 <httpErrors existingResponse="PassThrough"/> 

I think this will happen if in your UnknownUrl action you set Response.StatusCode = 404; . By default, IIS sees that you are returning an error code, so a default error message is displayed, which you can override using this configuration setting.

I'm not sure if this will be different on the local remote computer, but it might be worth a try.

+3
source

Can you try setting the host header - I believe this is what causes the difference between local and production:

 new { controller = "CatchAll", action = "UnknownUrl", host = HttpContext.Current.Request.Url.Host} 

Register this route from Application_BeginRequest Global.asax . Also, make sure this is done only once - perhaps with a check similar to:

 if (routes["UnKnown"] == null) { routes.MapRoute( name: "UnKnown", url: "{*url}", defaults: new { controller = "CatchAll", action = "UnknownUrl", host = HttpContext.Current.Request.Url.Host} ); } 
+1
source

All Articles