【问题标题】:Issue ASP.Net URL Routing - the route on which I redirect 2nd time is not correct问题 ASP.Net URL 路由 - 我第二次重定向的路由不正确
【发布时间】:2013-10-03 20:05:40
【问题描述】:

我在 ASP.Net URL 路由中遇到问题。以下是 Global.asax 代码:

public static void RegisterRoutes(RouteCollection routeCollection)
    {
        routeCollection.MapPageRoute("Project", "{dealname}/{city}/{projectname}/{projectid}", "~/projectpage.aspx");
        routeCollection.MapPageRoute("Home", "home/{dealname}/{city}", "~/index1.aspx", true, new RouteValueDictionary { { "dealname", "property-for-sale" }, { "city", "Ahmedabad" } });
        routeCollection.MapPageRoute("ProjectType", "result/{dealtype}/{searchstring}", "~/result.aspx");
    }

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

    }

当我打开站点路由“主页”的 URL 时,它运行良好。但是当使用 Response.Redirect 重定向到路由“ProjectType”时,前一个 URL 的“home/”部分仍然存在,它保留在同一页面上,并且在 URL 中显示 /home/result/{dealtype}/ {searchstring} 而不是 /result/{dealtype}/{searchstring}。

请指导我缺少什么或应该做些什么来解决这个问题。

谢谢, 蒙贾尔

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    我找到了解决方案。不要使用 Response.Redirect(),而是使用 Response.RedirectToRoute()。该函数专门用于实现 URL 路由。

    参考链接:http://msdn.microsoft.com/en-us/library/dd992853.aspx

    谢谢, 蒙贾尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多