MVC default document under folders
So in IIS you can set the 开发者_开发知识库default document for all site folders to be say "index.aspx".
In MVC how do I do this across a) all directories or failing that b) one directory at a time.
I have a page in [Views]/[Search]/[index.aspx]
This url works - www.[mysite]/search/index but I can't get it to work under - www.[mysite]/search
I have tried adding this into global.asax > RegisterRoutes
routes.MapRoute(
"Search",
"{action}",
new { controller = "Search", action = "Index" }
);
MVC doesn't use a default document, but a default route.
Your route above shows us that the default page when someone visits your website (http://example.com) will be the Index
view contained within the search
directory.
The default route that gets generated with a new MVC project looks like this
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
What this means is that your routing structure would look like
- http://example.com/ (showing the "index" view within the "home" folder)
- http://example.com/about/ (showing the "index" view within the "about" folder)
- http://example.com/about/contact (showing the "contact" view within the "about" folder)
Normally you don't need this route. The default route should work fine as it specifies a default controller and action which you could modify to match your requirements. Thus if the user requests /
this default controller and action should be executed. This would work out of the box on IIS7 but on II6 it won't work because you cannot have extensionless urls by default. You might take a look at the following blog post if you are running on IIS6.
精彩评论