如何在网址栏中提供重复的名称

时间:2012-12-13 05:47:25

标签: asp.net-mvc-3 url c#-4.0 asp.net-mvc-routing

如何复制网址栏中的名称。例如,我有products controllerindex method。现在,在我的项目中,我正在运行localhost:89733/Products/Index。但是,而不是Products/Index想要给另一个名称运行相同的action method。我怎样才能做到这一点。我的意思是我不想将控制器信息泄漏给其他人。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:2)

您可以配置自定义路线:

routes.MapRoute(
    "ProductsRoute",
    "mycustomproductsname/{id}",
    new { controller = "Products", action = "Index", id = UrlParameter.Optional }
);

现在,当您导航到mycustomproductsname/123时,Index控制器的Products操作将被执行并作为id参数传递123。

答案 1 :(得分:0)

我希望路由可以解决Global.asax文件应用程序启动事件中的目的

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    RegisterRoutes(RouteTable.Routes);


}   


public void RegisterRoutes(RouteCollection routes)
{
    //Treeview routing
    routes.MapPageRoute("Home", "User/Dashboard", "~/Products/Index");
    routes.MapPageRoute("SearchCustomer", "User/Search-Customer", "~/Products/SearchCustomer");



} 

我希望你能要求这个并且它可以帮助你

相关问题