how can we point the default file to something like index.html instead of the default action Home/Index
4 Answers
In IIS configure the default document to be index.html at the top of the list?
Or you could add an IgnoreRoute to your global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.RouteExistingFiles = true;
routes.IgnoreRoute("{file}.html");
...
1 Comment
I found that under IIS 6 at least the default document pickup was interfered with when you used a wildcard catchall to route most requests into the MVC.
My solution (just for the root path in my case) was as follows: (in global.asax)
if (Request.Path == "" || Request.Path == "/") { Response.Redirect(Request.Path + "index.htm",true); return; }
This picked up the request and redirected it to the correct location. Rewriting the path using Context.RewritePath(Request.Path + "index.htm"); instead of the redirect also seems to work. A further revision would probably be to see if the final character of the path is '/' and if so check whether the corresponding file (thatpath/index.htm) exists and redirecting if it does... this would effectively allow MVS to keep working while providing logic so any folders that do exist that have a default document like that will serve that.
Comments
You can change the default controller action by adding or changing a route in the Global.asax.cs file of your project.
In the template, the following is included:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = null });
If you want to point to a different controller action by default, just change the values in the anonymous type on the fourth line of code above.