例如:当前URL:http://www.testsite.com/home?pageId=1002
所需网址:http://www.testsite.com/1002/home/
因此,显示在地址栏中的URL将是所需的URL,而实际工作的URL将是当前URL。
我已经在我的项目的Global.asax文件中尝试了网址路由,但似乎对我不起作用。
我真正想要的是把URL放在这里。
提前谢谢。
发布于 2013-07-04 03:18:46
ASP.NET MVC4提供了编写应用程序的工具箱方式。您在浏览器中看到的url来自于将URL转换为应用程序路由以及将应用程序路由转换为url的路由。
1)默认的ASP.NET MVC4模板项目在App_Start文件夹下有一个名为RouteConfig的文件,您必须在其中配置应用程序的路由。
2)路由具有优先顺序,因此,将此路由放在默认路由之前:
routes.MapRoute(
name: "RouteForPageId",
url: "{pageId}/{action}",
//controller = "Home" and action = "Index" are the default value,
//change for the Controller and action that you have
//pageId is the parameter from the action that will return the page
defaults: new { controller = "Home", action = "Index" }
);现在您可以输入myappdomain/1220/index作为示例。
希望这能对你有所帮助!请看这里了解更多信息ASP.NET Routing!
https://stackoverflow.com/questions/17441861
复制相似问题