July 30, 2009

ASP.NET MVC Install on IIS6

OK, the fun part of MVC is installing it on IIS6. You can find a bunch of solutions if you google for it, but I wanted to get the two that I tried here on my blog.
  1. The easy option is to use a wildcard mapping for aspnet_isapi.dll. You simply map the “.mvc” extension on this new virtual directory and ensure the “Verify file exists” setting is turned off. This tells IIS 6 to process all requests using ASP.NET, so routing is always invoked.

  2. Second option is to use a url-rewriter. A free one can be found here. Download and install and then set up the httpd.ini file like this:
[ISAPI_Rewrite]

# Defend your computer from some worm attacks
RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]

# -----------------------------
# http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
# -----------------------------
# If you're hosting in a virtual directory, enable these lines,
# entering the path of your virtual directory.
UriMatchPrefix /MySite
UriFormatPrefix /MySite

# Add extensions to this rule to avoid them being processed by ASP.NET
RewriteRule (.*)\.(css|gif|png|jpeg|jpg|js|zip) $1.$2 [I,L]

# Normalizes the homepage URL to /
RewriteRule / /default.aspx [I]

# Prefixes URLs with "rewritten.aspx/", so that ASP.NET handles them
RewriteRule /(.*) /rewritten.aspx/$1/ [I]
# -----------------------------
# End of solution
# -----------------------------
You may need to play with the rewrite ... I know I had to for it to work for me. In the end I chose the rewrite option since I did not want the .mvc extension.

No comments:

Post a Comment