Using a URL with a suffix in asp.net mvc

Source: Internet
Author: User

In the ASP.net webform many people have done through URL rewrite so that the URL does not have a suffix, this time we do exactly the opposite. Suppose we need to set the URL suffix to shtml to create the default project for the new ASP.net MVC project as an example. If you want to access the landing page, the URL matches the login Action for the Http://localhost/Account/Login,Account matching account controller,login. If we want to change the URL to http://localhost/Account/ Login.shtml, the action becomes login.shtml without changing the route, obviously unable to find this action, so there is a 404 error, we have to do is still resolve the action to login, so we will be the default route change to

1routes. Maproute (
2 "Default",
3 "{controller}/{action}.shtml",
4 new{controller= "Home", action= "I Ndex ", id=" "}

At this point, login in login.shtml is exactly the corresponding {action} so it will invoke the login action in account controller, which is our goal. If you want to use a different suffix, simply change. shtml to. aspx or. 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.