Question

I am probably overlooking something really simple here but I am trying to redirect all bad URLs to an action that filters the URL based on conditions and then either 301 redirects to a suitable page or issues a 404 page.

To this end I have a route like this at the end of my route table:

routes.MapRoute("Error", "{*url}", new { controller = "Main", action = "Error" }); 

And an action like this:

public ActionResult Error(string url)
{
        if (/* Conditions are met... */)
        {
            Response.Status = "301 Moved Permanently";
            Response.AddHeader("Location", /* Destination URL */);
            Response.End();
        }

        Response.StatusCode = 404;
        return View(/* 404 page... */));
}

This works perfectly locally.

However, when deployed to IIS6, URLs that don't include .mvc (e.g. oldfile.php) are never sent to the ASP.NET process for routing.

Is there a simple solution / am I overlooking something?

EDIT : This is related to this question, however under IIS6 URLs without .mvc are not being sent for ASP.NET MVC processing.

Was it helpful?

Solution

More than likely when you deployed to the Server, ASP.Net is not being invoked.

I would setup wildcard mapping in IIS so your requests will use ASP.Net to serve the requests.

Open IIS manager, right-click your app, go to Properties, then Home Directory tab, then click Configuration. Under Wildcard application maps, click Insert (not Add, which is confusingly just above), then enter C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll for “Executable”, and uncheck Verify that file exists.

For more information please visit the source that helped me with this issue at: http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top