路由设置:




自定义默认路由
自定义默认路由

中间件 app.UseMvcWithDefaultRoute()
1.wwwroot 网站的根目录 自动被服务器与域名进行映射
映射必须保存在服务器中
url路径一致
服务器请求文件, 映射, 返回 http 文件
MVC路由系统
自定义默认路由
使用中间件:
app.UseMvc(routes=>{
routes.MapRoute(name:"default",template:"{controller=Home}/{action=Index}/{id?}")
});
ASP.NET MVC系统默认路由
使用中间件:
app.UserMvcWithDefaultRoute();
映射默认路由:
{域名}/{Contorller=Home}/{Action=Index}/{value?}
默认路由
中间件:app.UseMvcWithDefaultRoute();
映射默认路由:{域名}/{Controller=Home}/{Action=Index}/{value?}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "defalut",
template:"{controller=Home}/{action=Index}/{id?}"
==app.UseMvcWithDefaultRoute();
}
使用中间件或者映射默认路由都可以
传统的路由:
映射资源必须保存在服务器中
url的相对路径必须于请求路径一致
无法服务动态文件
文件必须带有后缀
暴露服务器的文件结构
ASP.Net MVC路由系统
无需文件真正保存在硬盘上
访问文件无需后缀
url结构于服务器文件夹结构无关
app.UseMvc(routes=>
{
routes.MapRoutes(
name:"default",
template:"{controller=Home}/{action=Index}/{id?}"
);
==app.UseMvcWithDefaultRoute();
}