zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Asp.net mvc 配置伪静态方法

2023-04-18 14:56:19 时间

1.安装UrlRewriter

 

 

 

 

2.

<system.webServer>  这个节点下面添加配置

<modules runAllManagedModulesForAllRequests="true" />

 

3.配置RouteConfig

 

 

 

具体配置如下:

  routes.MapRoute(

                       "Action1Html", // action伪静态

                        "{controller}/{action}.html",// 带有参数的 URL

                        new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值

            );



            routes.MapRoute(

               "ActionHtml", // action伪静态

               "{controller}/{action}.html/{id}",// 带有参数的 URL

               new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值

           );



            routes.MapRoute(

                       "IDHtml", // id伪静态

                       "{controller}/{action}/{id}.html",// 带有参数的 URL

                       new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值

       );


            routes.MapRoute(

              "ControllerHtml", // controller伪静态

              "{controller}.html/{action}/{id}",// 带有参数的 URL

              new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值

          );

            routes.MapRoute(

               "Root",

               "",

               new { controller = "Home", action = "Index", id = UrlParameter.Optional });//根目录匹配



            routes.MapRoute(

                name: "Default",

                url: "{controller}/{action}/{id}",

               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

            );