基本信息
源码名称:Asp.Net MVC url重写_静态化实现(伪静态)
源码大小:15.52M
文件格式:.zip
开发语言:C#
更新时间:2019-02-02
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍



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

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

            routes.MapRoute(
                name: "Action1Html", // action伪静态    
                url: "{controller}/{action}.html",// 带有参数的 URL    
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }// 参数默认值    
            );

            routes.MapRoute(
                name:"IDHtml", // id伪静态    
                url:"{controller}/{action}/{id}.html",// 带有参数的 URL    
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }// 参数默认值    
            );

            routes.MapRoute(
                name: "ActionHtml", // action伪静态    
                url: "{controller}/{action}.html/{id}",// 带有参数的 URL    
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }// 参数默认值    
            );

            routes.MapRoute(
                name: "ControllerHtml", // controller伪静态    
                url: "{controller}.html/{action}/{id}",// 带有参数的 URL    
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }// 参数默认值    
            );

            routes.MapRoute(
                name:"Root",
                url: "",
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }//根目录匹配    
            ); 

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //);
        }
    }
}