我有一个app root:localhost / Product
我想在我的根网址上附加一个字符串 本地主机\字符串名称
stringName将被读取frm配置文件并设置为url的末尾,后跟控制器和操作名称 例如:localhost \ Product \ stringName \ controller \ Action 和stringName需要通过所有重定向的应用程序保存。
请帮忙
答案 0 :(得分:0)
退房:http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC
您需要对自定义网址路径进行一些研究
答案 1 :(得分: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 }
);
);