In the previous articleArticleDescribes how to disable controller (http://www.cnblogs.com/Snowdreams/archive/2008/10/18/1314188.html) in the URL of an ASP. net mvc project. This article describes how to enable a URL with a suffix by setting route.
In ASP. NET webform, many people have done URL rewriting so that the URL does not contain a suffix. This time we did the opposite. Suppose we need to set the URL suffix to shtml, and take the default project when creating an ASP. net mvc project as an example. To access the logon page, the URL is http: // localhost/account/login. The account matches the account controller, and the login matches the login action. If we want to change the URL to http: // localhost/account/login.shtml, the action will be changed to login.shtml without changing route. obviously, this action cannot be found, so the 404 error occurs. What we need to do is to resolve the action to login, so we changed the default route
1 Routes. maproute (
2 " Default " ,
3 " {Controller}/Alibaba action=.shtml " ,
4 New {Controller = " Home " , Action = " Index " , ID = "" }
Finally, login in login.shtml exactly corresponds to {action}, so it will call the login action in account controller, which achieves our goal. If you want to use another extension, you only need to change .shtmlto .aspxor .html.