I have added an MVC3 web application to an existing website that consists of plain old html files. This works great when you request a specific file but what didn't occur to me was that by changing the site to use .Net 4 it no longer took any notice of the default documents setting in IIS (IIS 6 in this case). So for example I can request www.something.com/index.html but if I request www.something.com I get a resource not found error page. Is there a MapRoute in Global.asax I can specify to map the site route url to index.html?
-
Did you read the Phil Haack [blog post](http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx) I have linked to in [my answer](http://stackoverflow.com/questions/7460870/how-to-get-a-default-html-page-on-mvc3-site/7460903#7460903) about configuring your IIS 6.0 in order to support extensionless urls which by default IIS 6.0 doesn't support? – Darin Dimitrov Sep 18 '11 at 20:30
-
Yes I did but I'm not sure it was entirely relevant to my problem. I just want to redirect requests to the site root to index.html. Phil's post was more about mapping to controllers. I'll go back and take another look tonight. – David Clarke Sep 18 '11 at 21:03
-
if you want to execute some controller action when the user requests `http://www.something.com/` you definitely need a wildcard mapping as explained by Phil Haack. If you want to serve a static HTML page then simply add this html page as default document in the properties of the virtual directory in the IIS console. – Darin Dimitrov Sep 18 '11 at 21:04
-
That's the problem I'm trying to fix. The default document is defined correctly for the site. When I set .Net Framework to version 2 it works correctly but when I set it to version 4 it doesn't redirect to index.html. That's why I'm thinking the IgnoreRoute option may be worth trying. Unfortunately I won't be in a position to check until this evening (UTC+12:00) – David Clarke Sep 18 '11 at 21:19
4 Answers
Looks like something has changed, I had to do
routes.IgnoreRoute("");
ASP.NET complained about the route starting with "/"

- 4,828
- 2
- 27
- 19
-
Confirmed: `routes.IgnoreRoute("/")` gives an error - this answer works as intended. – Matt Oct 29 '13 at 18:06
routes.IgnoreRoute("");
Allows the request to fall through to the default documents defined in the site configuration. I only have a single controller and route in this project that I use for ajax requests from the client. I want the rest of the site to continue to behave as it did when it was just plain html. With routes.IgnoreRoute("") the MVC3 app ignores the request which allows IIS to return the default document. Thanks all for your suggestions.

- 12,888
- 9
- 86
- 116
-
1This just throws an error in MVC3: "The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character. Parameter name: routeUrl" – Gullbyrd Aug 17 '12 at 18:36
-
1
-
-
Apologies, this was a solution I used at the time but clearly this has been changed in an update. Have updated the answer to reflect. – David Clarke Jan 11 '14 at 07:28
in global.asax you can try to define a rules like this one
routes.MapRoute("", "index.html", new { controller = "Home", action = "Index" });
But I'm afraid that with IIS 6 you have to handle the Wild card mapping
.

- 9,213
- 4
- 49
- 71
-
I'm not sure if I expressed my question clearly. I don't want to map a request for index.html to a controller. I want to redirect a request to the site root to index.html. – David Clarke Sep 18 '11 at 21:05
-
After the comments in your answer I understand your problem. Try looking at this answer http://stackoverflow.com/questions/1149750/using-asp-net-routing-to-serve-static-files/3112192#3112192 – Iridio Sep 19 '11 at 05:07
That's normal. IIS 6.0 does not support extensionless urls. You will need a wildcard mapping as explained by Phil Haack.

- 1,023,142
- 271
- 3,287
- 2,928