Use a URL with a Suffix in ASP. NET MVC

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.