【问题标题】:HttpUtility.UrlPathEncode(Urlstring) not working- Page not found errorHttpUtility.UrlPathEncode(Urlstring) 不起作用 - 找不到页面错误
【发布时间】:2018-01-24 15:14:03
【问题描述】:

我正在使用 HttpUtility.UrlPathEncode 来编码 url。当命中编码的url结果是找不到页面时

HttpUtility.UrlPathEncode("http://example.com/Fundamentals of Data Structures C++")

编码的网址

http://example.com/Fundamentals%20Of%20Data%20Structures%20C++

找不到页面

请帮我解决这个问题

【问题讨论】:

  • 如果你转到"http://example.com/Fundamentals of Data Structures C++",页面是否正确打开?如果是,请查看您的路由设置。
  • 我正在使用 URL 路由。如果使用 http:example.com/Fundamentals of Data Structures C++ 仍然找不到页面错误。如果使用没有任何特殊字符的编码网址,则可以正常工作
  • “没有任何特殊字符”你的意思是最后没有++
  • 请查看直播http://www.booksbecho.in/Operation%20System%20Concepts%208Th%20Edition?Id=1948427714http://www.booksbecho.in/Fundamentals%20Of%20Data%20Structures%20C++?Id=1197287199

标签: asp.net


【解决方案1】:

+ 符号是 URL 中的一种特殊符号。它用于表示空间。您应该对+ 符号进行编码。它的值应该是%2B。例如。 HttpUtility.UrlPathEncode(someURL).Replace("+","%2B")

【讨论】:

  • 运气还是一样http://www.booksbecho.in/Fundamentals%20Of%20Data%20Structur‌​es%20C%2B%2B?Id=11972871‌​99
  • 好的。您的路由设置似乎只是忽略了 URL 中的 + 标志。 http://www.booksbecho.in/Fundamentals%20Of%20Data%20Structures%20C?Id=1197287199 所以使用以下内容:HttpUtility.UrlPathEncode(someURL).Replace("+","")
  • 顺便说一句,请检查您的搜索。例如。如果我搜索 C++ 它会破坏 http://www.booksbecho.in/all-india/all-categories/1/c%2B%2B 确保你也从那里删除 + 标志。
  • 谢谢。现在可以使用了。但是如果在 url 中使用其他特殊字符而不是 + 呢?
猜你喜欢
  • 2014-12-07
  • 1970-01-01
  • 1970-01-01
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
  • 2011-08-06
  • 2018-07-24
  • 2016-04-07
相关资源
最近更新 更多