且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MVC中重写Url

更新时间:2023-02-24 10:54:45

请试用此代码



 routes.MapRoute(
DefaultCustom // 路线名称
{action} / {Name}, // 包含以下内容的网址操作和类别
new {controller = 帐户,action = 操作,Name = UrlParameter.Optional } // 参数默认值
);





请查看这篇文章



MVC中的路由 [ ^ ]


Currently the url structure for the sign - up page is:

http://www.ABC.com/Account/Create?subscr=1

I'm wondering how hard it would be to create a "friendly url" for an existing product so it would read something like:

http://www.ABC.com/DiscountOffer

Please try this code

routes.MapRoute(
           "DefaultCustom", // Route name
           "{action}/{Name}", // URL with Action and category
           new { controller = "Account", action = "Action", Name= UrlParameter.Optional } // Parameter defaults
       );



Please check this article

Routing in MVC [^]