RouteConfig.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcRazorDemo
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //路由规则:
            //1、可以有多条路由规则
            //2、路由规则是有顺序的。前面被匹配了之后,后面就没有机会了。

            routes.MapRoute(
              name: "Default2",//作为路由规则的key,一定不能重复
              url: "{controller}-{action}/{id}",//请求后台URL规则
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
                //constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
                //namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
            );

            //注册一条路由规则
            routes.MapRoute(
                name: "Default",//作为路由规则的key,一定不能重复
                url: "{controller}/{action}/{id}",//请求后台URL规则
                //http://localhost:23017/Home-Index
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
                //constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
                //namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
            );


            //routes.MapRoute(
            //    "酒店列表页",//路由规则名字
            //    "hotels/{action}-{city}-{price}-{star}", //路由规则的URL格式
            //    new { controller = "Hotel", action = "list", city = "beijing", price="-1,-1", star="-1" },//默认值
            //    new { city=@"[a-zA-Z]*",price=@"(\d)+\,(\d)+", star="[-1-5]"}
            //);
            
            hotels/所有匹配
            //routes.MapRoute(
            //    "酒店首页",
            //    "hotels/{*写什么都可以}",
            //    new { controller = "Hotel", action = "default", hotelid = "" }
            //);

            //routes.MapRoute(
            //    "网站首页",
            //    "{*values}",
            //    new { controller = "Home", action = "index"}
            //);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值