在Asp.net MVC中,对于一个请求,是通过路由找到对应的Controller类中的对应Action,并与model进行交互,最后返回到view。

就是说Asp.net MVC是用Route来定义各种URL到实际处理程序之间的映射的。

在处理请求之前,在Global.asax.cs文件的Application_Start中注册路由

public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}

然后在RouteConfig类中

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}

应用程序默认为路由增加了2个路由对象:

1. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  这个路由是用于忽略特殊请求的路由,这个路由忽略所有扩展名为.axd的请求。

2. routes.MapRoute(....);这个路由可以映射任何符合{controller}/{action}/{id}模式的URL,提供了一个默认的参数。

最新文章

  1. vue-router2.0 组件之间传参及获取动态参数
  2. golang调用EXE
  3. kubernetes多节点部署解析
  4. 基本概率分布Basic Concept of Probability Distributions 5: Hypergemometric Distribution
  5. 【6_100】Same Tree
  6. 写了个Linux包过滤防火墙
  7. 浅谈Javascript 数组与字典
  8. hdu4431 Mahjong 枚举搜索。。
  9. CSU 1808 地铁
  10. BZOJ 1832: [AHOI2008]聚会( LCA )
  11. Hibernate 配置详解(12) 补充
  12. JS 修改元素
  13. 浅谈html入门
  14. UUID错误
  15. Java获得系统的外网IP
  16. An internal error occurred during: "Retrieving archetypes:". GC overhead limit exceeded
  17. 用C语言做一个横板过关类型的控制台游戏
  18. git tag 打标签
  19. datatables后端分页
  20. vue(v-html)和scss的使用问题

热门文章

  1. Linux命令总结_文件查找之grep
  2. 提升 web 应用程序的性能(一)
  3. 加载外部JavaScript的最佳方法
  4. 将服务器上的某些特定日志统一保存至XPS文件
  5. Scrum会议10(Beta版本) 补交
  6. NOJ 1651 Red packet(二分)
  7. C++ 中的模板类声明头文件和实现文件分离后,如何能实现正常编译?
  8. Android消息处理机制
  9. Maven问题总结:could not resolve archetype xxxxxxx from any of the configured repositories
  10. [ZZ] HDR the bungie way