views:

30

answers:

2

I have a project using Asp.Net 3.5 and MVC 1.

Everything runs perfectly on my local IIS, but not after I deployed it to the hosted server.

The web server is IIS7 with integrated pipeline activated (according to the hosting company).

When I go to the root of the web site, www.site.com, the default.aspx makes a redirect to a controller like so:

public void Page_Load(object sender, System.EventArgs e)
{
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath + "Controller.mvc/Action", false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}

This works and the correct view is shown. However, when I type the same address in the browser, www.site.com/Controller.mvc/Action I get a 404.0 error. So it seems the MvccHttpHandler is not invoked correctly(?).

The web.config is set up with runAllManagedModulesForAllRequests="true", and a MvcHttpHandler is configured to handle .mvc extensions.

What am I doing wrong, any ideas?

A: 

Here's a good article which covers different deployment scenarios. There are no particular steps required when deploying to IIS 7 in integrated mode. You don't need a default.aspx file and association of MvcHttpHandler with the .mvc extension in your web.config. Here's how your routes might look like if you want to handle both extensionless routes in IIS 7.0 and the .mvc extension in IIS 6.0.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

// This is for IIS 6.0
routes.MapRoute(
    "DefaultWithExtension",
    "{controller}.mvc/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

// The default extensionless route working with IIS 7.0 and higher
routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

The .mvc extension is needed only for IIS 6.0:

<httpHandlers>
    <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
Darin Dimitrov
Thank you for your advice. However, my problem still persists. Any requests to my controllers gives me a 404.0 error, regardless if I use mvc-extensions or not. The only way I could get it to work was by manually process the request via the default.aspx, which made me believe that the problem was with the MvcHttpHandler.
Tan
A: 

Turned out my hosting company did not run my application in integrated mode, even though they told me. Solved my problems, but I also got a few helpful tips from Darin.

Tan