2014-05-23 54 views
0

我有一个应用程序根目录:本地主机/产品添加一个字符串URL

我想一个字符串连接到我的根URL 本地主机\字符串名称

字符串名称将被读取FRM配置文件和设置url结尾,然后是控制器和动作名称 例如:localhost \ Product \ stringName \ controller \ Action 和stringName需要通过应用程序保留所有重定向。

请帮

回答

0

您可以更改默认的路由是这样的:

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

从你RouteConfig .cs文件。 或者,如果您将应用程序从mvc 4升级到mvc 5,则可以使用属性路由,您可以阅读更多内容here

更新:

试试这个在默认路由:

string stringName = WebConfigurationManager.AppSettings["stringName"].ToString() 
routes.MapRoute(
    name: "Default", 
    url: stringName + "/{controller}/{action}/{id}", 
    defaults: new { controller = "Page", action = "Index", id = UrlParameter.Optional } 
); 
); 
+0

以上航线将不匹配because..my要求DOE没有字符串名称开始with..it大干快上sessionStart加入Global.asax中。 – user3667110

+0

然后你可以像这样实现IRouteConstraint:http://stackoverflow.com/questions/16026441/dynamic-routes-from-database-for-asp-net-mvc-cms – TotPeRo