参考:https://www.cnblogs.com/zeusro/p/RouteConfig.html
http://www.cnblogs.com/xclw/p/6676886.html
注意点:
1、自定义路由配置
.net Core
asp.net
(url:View/{*path}该种写法意思为,View/后的都是Action的参数)
该配置为只要url/View/xx/yy/zz…这类链接都会走到ViewController类的
public ActionResult Index(string htmlPath)
{
}
方法中,而参数htmlPath的值是"xx/yy/zz"
2、asp.net mvc与.net core mvc的区别
1) “url/View/xx/yy/zz.html”(带后缀)此种写法
asp.net mvc中,IIS会直接访问静态文件,而不会走路由,故不会走到Controller中,除非在web.config中配置
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" /><!--将IIS的静态文件处理改为走路由--!>
.......
</system.webServer>
</configuration>
但该修改会导致所有的静态文件都会走到路由,这样会增加服务器的压力,此时可以在RouteConfig类中增加如下配置
1 public class RouteConfig
2 {
3 public static void RegisterRoutes(RouteCollection routes)
4 {
5 routes.RouteExistingFiles = true;
6 routes.IgnoreRoute("Content/{*relpath}");//指定目录不走路由
7 routes.IgnoreRoute("Scripts/{*relpath}");//指定目录不走路由
8 }
9 }
可将某此目录下的请求绕过路由直接访问;
而.net core mvc中,因没有IIS的静态文件处理系统,故所有的请求都会走路由,但是可以配置相应的静态文件,以节省路由的资源占用,配置如下
将默认的wwwroot目录配置为静态资源:
自定义静态目录方法如下: