views:

5510

answers:

6
+13  Q: 

MVC .Net and IIS 5

What is the best way to get hosting of an MVC.Net application to work on IIS 5 (6 or 7). When I tried to publish my MVC application, all I seem to get is 404 errors. Iv done abit of googleing and have found a couple of solutions, but neither seem super elegant, and I worry if they will be unusable once I come to use a shared hosting environment for the application.

Solution 1

  1. Right-click your application virtual directory on inetmgr.exe.
  2. Properties->Virtual Directory Tab-> Configuration.
  3. Add a new mapping extension. The extension should be .*, which will be mapped to the Executable C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll, or the appropriate location on your computer (you can simply copy this from the mapping for .aspx files). On the mapping uncheck "check that file exists".
  4. 3 X OK and you're good to go.
  5. If you want, you can apply this setting to all your web sites. In step1, click on the "Default Web Site" node instead of your own virtual directory, and in step 2 go to the "Home Directory" tab. The rest is the same.

Seems a tad hacky to route everything through ASP.NET

Solutions 2

Edit the mvc routing to contain .mvc in the url and then follow the steps in solutions 1 based around this extension. Edit: The original image link was lost, but here it is from Google's Cache:

alt text

+1  A: 

Have you tried adding .aspx to the end of the controller name?

It worked for this.

IainMH
So thats is basically solutions 2 then, thanks for point out the other question though.
Dan
Very similar but if you're using shared hosting you wouldn't be able to add the mapping extension. By adding aspx you should be golden for any site that runs 3.5
IainMH
+8  A: 

Answer is here

If *.mvc extension is not registered to the hosting , it will give 404 exception. The working way of hosting MVC apps in that case is to modify global.asax routing caluse in the following way.

routes.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary (new{ controller = "YourController"} ) });

In this way all your controller request will end up in *.mvc.aspx, which is recognized by your hosting. And as the MVC dlls are copied into your local bin , no special setttings need to be done for it.

Dan
Does this go before or after the `routes.MapRoute("Default","{controller}/{action}/{id}",new { controller = "Home", action = "Index", id = "" }); //?`
Maslow
+6  A: 

I think either way you'll have to do Solution 1.

Consider the HTTP Request pipeline.

  1. A request comes into IIS.
  2. IIS checks port/host header to see if it has a web site set up to capture requests for that host header/port.
  3. IIS investigates the file extension of the request (.php, .asp, .aspx) and hands it off to an ISAPI that can handle that type of request.

Only at this point does ASP.NET (or a PHP runtime) kick in. If IIS does't have that mapping then it'll never hand off the request to the ASP.NET runtime and the request will never reach your code. That's why you need that glob (*) mapping to the ASP.NET ISAPI.

ASP.NET MVC framework urls often end with no file extension at all. If you want these requests to get handled by ASP.NET (or some other runtime) you have to map all requests regardless of the file extension to that ISAPI (ie. aspnet_isapi.dll).

This is often also done for HttpHandlers that need to serve off media like .jpg, .gif. For the handler to be hit it needs to get mapped to your code even though .jpg isn't a "normal" ASP.NET file extension.

HTH,
Tyler

Tyler
A: 

I got "Server Application Unavailable" when i tried mapping .* to aspnet_iasp.dll

Jack
You have to use the old IIS 5.1 Manager not the 6.0 Manager
despart
A: 

FYI:On server 2003 (developing an app that had to connect to the RPS), it didnt' allow me to add the extension .*, I used the alternate solution modifying the route clause, and that worked.

Eric Brown - Cal
A: 

If are still interested, I've written an article about it. http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx It is not elegant but It is only solution. I've used it and it works.

Alex Ilyin
ironically, link is 404'd :(
Chris McCall
Indeed, thanks for commenthttp://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx
Alex Ilyin