A temporary solution for disabling access to some files on the homepage due to the development of default routes using MVC

Source: Internet
Author: User

The development of Mvc4 is involved in recent development. The default routing function is very good, but there are many problems in practical application. For example, we visit a website http://www.abc.com, although the routing will help automatically turn to the Home/Index DIRECTORY, but the address of the browser does not change, this problem occurs. If you still have other sub-directories on the site, or the mvc application is executed in the virtual directory, the page will show ".. /a subdirectory name/file name "cannot be accessed. The page is normal only when you enter the complete path in the address bar, such as http://www.abc.com/home/index. At present, I have personally studied the problems caused by the mvc Routing Mechanism (of course, it may be my personal habit to set the directory). No matter what the cause is, the problem does occur. I have found a lot of problems on the Internet, and some netizens have asked me, but no one has answered them. How many people are using mvc4? Or what is the situation. No matter what, I developed a temporary solution. The principle is to manually complete the simplified Homepage Address and implement it using JS, you only need to add the code to the top position of the Home/Index page for priority execution. The Code is as follows:

1 <script> 2 var loc = window. location. href. toString (); 3 if (loc. indexOf ("Home") <= 0) {4 if (loc. lastIndexOf ("/") = loc. length-1) {5 window. location. href = loc + "Home/Index"; 6} 7 else {8 window. location. href = loc + "/Home/Index"; 9} 10} 11 </script>

The code is not easy to use. It is just a temporary solution for the individual to solve the problem. Due to limited time, I did not find a better solution. Please kindly advise me if you have any better methods. Thank you!

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.