How to have specific routing in asp.net mvc 4
本文关键字:asp net mvc in routing to have specific How | 更新日期: 2023-09-27 18:25:07
我想知道如何在MVC.net 4中有特定的地址我的web应用程序中有3种url类型1-www,site.com/rss.xml2-ww.site.com/amir(这种类型的地址是为我的用户保留的,我想输入我的网站的用户名,以便为我的每个用户创建一个配置文件地址)3-ww.site.com/article/detail/1
我的RouteConfig文件如下
routes.MapRoute(
name: "RSS_route", // Route name
url: "rss.xml", // URL with parameters
defaults: new { controller = "Common", action = "RSS", area = "" } // Parameter defaults
, namespaces: new[] { "Clinic.WebUI.Controllers" }
);
routes.MapRoute(
name: "Doctor",
url: "{docname}",
defaults: new { controller = "Doctor", action = "Doctor", docname = "test" }
, namespaces: new[] { "Clinic.WebUI.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
, namespaces: new[] { "Clinic.WebUI.Controllers" }
);
routes.MapRoute(
name: "Article",
url: "{controller}/{action}/{id}/{subject}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, subject = UrlParameter.Optional }
, namespaces: new[] { "Clinic.WebUI.Controllers" }
);
但问题是,这3种url类型都不可访问,只有第2种有效如果有人能在这方面帮助我,我会很高兴
您是否看过MSDN,因为它们有一个非常合理的答案,在这里很有意义:https://msdn.microsoft.com/en-us/library/cc668201.aspx#Anchor_2
我所做的一切得到的结果是谷歌"ASP.net MVC 4路由",这是第三个结果。。。
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("",
"Category/{action}/{categoryName}",
"~/categoriespage.aspx");
}