在MVC中重写Url [英] Url Rewriting in MVC

查看:94
本文介绍了在MVC中重写Url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 目前    url   structure   for     sign    -    up   page  是: 

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

我是想知道 hard it create a friendly url 现有 product so it 读取 某事 如:

http: // www.ABC.com/DiscountOffer

解决方案

请试用此代码



 routes.MapRoute(
DefaultCustom // 路线名称
< span class =code-string> {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 [^]


这篇关于在MVC中重写Url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆