zoukankan      html  css  js  c++  java
  • 路由

    在App_Start文件夹下
    ====================================路由=================================================
    public class RouteConfig
    {
    public static void RegisterRoutes(RouteCollection routes)
    {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
    name: "Default",//这里一般是设置默认
    //url: "{controller}/{action}.html/{id}",这个可以知道html页面作为默认页面,不过需要在IIS中进行设置。。。
    //url: "{controller}/{action}.html/{id}-{id1}-{id2}",想传几个参数就加几个id..
    url: "{controller}/{action}/{id}", //这些是占位符,定义类url请求的格式规则,URL:“{控制器命名称(去掉伪后缀)}/{动作}/{参数值}”,
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } //这个是默认值,翻译后的URL:Home/Index,可以直接改写
    );
    //传入的是参数,所以也可以这样写,别人写了要看的懂
    // routes.MapRoute(
    // "Default",
    // "{controller}/{action}/{id}",
    // new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    //);

    }
    }
    ===========================================================================
    public class RouteConfig
    {
    //可以创建多条路由,用name属性值来区分不同路由
    //多条路由是有顺序的,前面的匹配后,后面的路由设置会无效。(其实就是多条包含在if()判断中的路由,有多个选择,但最后只能执行一个,排前的先判断)
    //友好的URL一般不要超过三层,比如www.xxx.com/xxx/xxx,第一层地址,第二层频道,第三层具体页面
    //多条路由设计规则:匹配范围越小,位置越靠前,比如登陆某个地址,无效后会自动匹配首页,这就是典型的路由设计

    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 },//.../Home/Index/id
    constraints: new { controller = @"一个正则表达式",id=@"" },//限制内容,一般是来现在id的值的
    namespaces: new string[] { "命名空间1","命名空间2","命名空间3" }//限制在指定的命名空间下查找地址
    );
    }
    //路由原理:1.路由规则对象:Route;2.路由数据对象:RouteData;3.路由规则集合:RouteCollection;4.路由表(静态的路由规则集合对象):RouteTable
    //一条URL地址过来,安照路由规则解析,解析后内容放到路由数据对象中,
    }

  • 相关阅读:
    Linux命令学习Day1
    谈谈VAssitX Snippet
    Visual Studio sort函数出现“invalid operator<”原因分析
    网络打印机共享设置
    Notepad++使用总结
    Leetcode顺时钟旋转90度
    搭建Docker版gitlab私有云
    获取安卓APP设备上报信息
    中间件服务测试点整理
    Jenkins主从模式添加节点机
  • 原文地址:https://www.cnblogs.com/it-xcn/p/5746337.html
Copyright © 2011-2022 走看看