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!