【问题标题】:Routing RouteValueDictionary url as second item problem路由 RouteValueDictionary url 作为第二项问题
【发布时间】:2011-03-12 21:22:19
【问题描述】:

我在将 URL 作为 RouteValue 项发送并使用 one`s 参数获取 GetVirtualPath 时遇到问题。

 var parameters = new RouteValueDictionary { 
       { CommonUrl.UrlParameters.AnyString, "ItISAnyString"},
       {CommonUrl.UrlParameters.ReturnUrl, "test/myPage/Index"}   
  };

并使用此参数获取 URL:

RouteTable.Routes.GetVirtualPath(null, anyRouteName, **parameters**).VirtualPath

所以我得到类似http://localhost/ItISAnyString/test/myPage/Index

的网址

系统无法识别此页面并出现 404。 但如果我手动执行这样的操作
http://localhost/ItISAnyString/test$myPage$Index 一切正常。 我认为应该有更好的方法来解决这个问题。

编辑

我发现对于这条 Route dont exist any RouteValueDictionary. I think that routing dont,如果有多个“/”符号,则第二个参数不存在。所以我会创建它,看看会发生什么。

编辑

我的大学很遗憾,在将 URL 作为参数发送时我必须对其进行编码。 好的,我做到了。 但现在我有 400 错误。 对我来说有点奇怪。

【问题讨论】:

    标签: c# asp.net c#-4.0 routing


    【解决方案1】:

    问题在于映射模式。 我刚刚在路线图中添加了 {*} 模式。 现在我的 global.asax 代码:

    routes.MapPageRoute(RouteName.Security.TestOne,
                                                Test, 
                                                "~/Web/Pages/Test/test.aspx", true);
    
      public static string Test = String.Format("{0}/{1}/{2}/{3}",
                                                                                "Test",
                                                                                "Testconfirm",
                                                                                "{" + CommonUrl.UrlParameters.FirstParam+ "}",
                                                                                "{*****" + CommonUrl.UrlParameters.Url + "}");
    

    这个概念名称是“在 URL 模式中处理可变数量的段” http://msdn.microsoft.com/en-us/library/cc668201.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多