About your host

Photo of your host - Charles Vallance Charles Vallance is a web developer with a slight case of OCD when it comes to nice clean standards compliant html and code.

Badges

twitter / cvallance
My articles have been featured in The Morning Brew - Daily .NET News and Views

Tag Cloud

more tags...
posted @ Thursday, January 10, 2008 10:01 AM

Ok, so while Scott Hanselman's MVC How-To Screencast is downloading, I thought I'd write a quick blog about getting ASP.NET MVC working on XP Pro and IIS 5.1. Although I haven't tested it, this fix should also work on IIS 6 boxes as well. When you create a default ASP.NET MVC project and use IIS 5.1 on XP Pro to serve up the pages, the default page (http://localhost/) loads up just fine but when you try and navigate to the 'About Us' page you'll get a 'The page cannot be found' 404 error. To remedy this (without going down the ISAPI filter road to get extensionless requests cranking) and use the .mvc extension as suggested, read on. Firstly you must edit the Global.asax.cs file and change the default routing rule to the following (you're just adding .mvc after [controller]).

RouteTable.Routes.Add(new Route
{
    Url = "[controller].mvc/[action]/[id]",
    Defaults = new { action = "Index", id = (string)null },
    RouteHandler = typeof(MvcRouteHandler)
});

Now after you've done this you'll have to associate the .mvc extension to ASP.NET. Firstly you must get to the properties of your site by right clicking on your 'Default Web Site' and selecting 'Properties' IIS51-site-properties

Then on the Home Directory tab, hit the Configuration... button

IIS51-site-configuration

To map the .MVC extension to the asp.net engine, we must find the location of the asp.net executable. The easiest way of doing this is to find where the .aspx extension is mapping to.

So to do this, on the 'Mappings' tab, on the 'Application Configuration' popup, find the '.aspx' extension and hit 'Edit'. From this box, copy the full executable location like so.

IIS51-excutable-copy

After you've done that, hit 'Cancel' and you should be back at the 'Application Configuration' popup. From this screen hit the 'Add' button and paste in the previous Executable location, then fill out the rest of the details like the screen shot below and make sure that the 'Check that file exists' check box is NOT ticked.

IIS51-extension-association

After that you should be ready to rock.

The great thing about the ASP.NET MVC routing engine is that you won't need to change any of the links, they will now be updated so that they include the .mvc extension, e.g. http://localhost/Home.mvc/About

Not pretty or ideal but it's quick and it works! I'll try and get a extensionless fix up soon.

Technorati Tags: ,,

And then he said...

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Travis
on 1/8/2008 9:01 AM
Any news on that "extensionless fix up"?

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by charles
on 1/8/2008 4:01 PM
Sorry, been far too busy doing other stuff...

I'll have a look at it over the next few days. Thanks.

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Henk
on 4/13/2008 12:04 AM
Hi Charles,

I have configured like you said above, but I still not to get it to work. I am using CTP2. The url's do not contain a .mvc extension although the routing has been defined with the .mvc extension. Any idea?

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Prakash
on 10/3/2008 4:10 AM
Hi Charles,
Instead of adding a .mvc extension into the IIS application mappings, couldn't we add a .* instead?
This way we could make do without using this the Rewrite utility.

The only disadvantage of this though is, IIS would intercept every request made to the web server. That would affect the performance. But with the powerful servers that we have today, wouldn't that small performance trade-off also seem insignificant?

Great article. Do let me know what you think of my reply.

Prakash.

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Mick
on 10/6/2008 9:10 PM
Hi Charles!
Have you try this approach on MVC Previe 5?
Your way works fine only at early version, but for Preview 5 it looks like MVC cannot locate corresponding controller.

Thank you in advance!

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Arron Green
on 11/20/2008 4:11 AM
for anyone trying to get this to work with MVC Beta:
follow everything above except for the global.asax.cs

use this:
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);

any requests to http://localhost/YourIISSiteName/default.aspx will fail with the following information:

The incoming request does not match any route.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The incoming request does not match any route.


a fast (non elegant) workaround would be to wrap default.aspx.cs code with a try/catch

try {
HttpContext.Current.RewritePath(Request.ApplicationPath);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
catch (HttpException) {
Response.Redirect("~/Home.mvc/Index");
}

anyone else get this working with a different solution?

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by Amin
on 12/9/2008 9:12 PM
Hi

instead .mvc u can put .* and then no need to change global.asax and there will be clean url

Regards
Amin

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
Posted by luis
on 6/12/2009 9:06 PM
Thanks, this worked great for me!

# Web Development

Gravatar
Posted by Peter
on 1/15/2010 7:39 PM
This post is very informative and i love reading it. I like to know about details of web development. Here i like to share about demellows.com that works for wed design and create good looking sites, adds a bit of flash in your presentation so that you can warm up your crowd and bring in the WOW factor. I find it very helpful.

# re: ASP.NET MVC on IIS 5.1 (XP Pro)

Gravatar
on 7/15/2010 9:56 PM
I believe in God so god is control and what happens here is only the smallest glimpse of something far greater that He has in mind for us..

And then I said...

Title *
Name *
Email
Url
Comment *  
Please add 1 and 8 and type the answer here: