【问题标题】:How to include quote characters as a route parameter? Getting "Illegal characters in path" message如何包含引号字符作为路由参数?收到“路径中的非法字符”消息
【发布时间】:2010-10-20 06:01:15
【问题描述】:

我在所有页面上都有一个搜索框。用户可以输入文本,然后单击搜索,他们最终会在搜索页面上显示结果。

当点击搜索时,包含文本框的表单被发送到以下路径:

http://localhost:2010/search/my%20search%20term

这行得通。但是如果我在字符串周围加上引号,

http://localhost:2010/search/%22my%20search%20term%22

这会失败,并显示错误消息“路径中的非法字符”。

使用以下堆栈跟踪:

[ArgumentException: Illegal characters in path.]
   System.IO.Path.CheckInvalidPathChars(String path) +7493413
   System.IO.Path.Combine(String path1, String path2) +40
   System.Web.Configuration.UserMapPath.GetPhysicalPathForPath(String path, VirtualDirectoryMapping mapping) +114
   System.Web.Configuration.UserMapPath.GetPathConfigFilename(String siteID, VirtualPath path, String& directory, String& baseName) +72
   System.Web.Configuration.UserMapPath.MapPath(String siteID, VirtualPath path) +30
   System.Web.Configuration.UserMapPath.MapPath(String siteID, String path) +31
   System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +297
   System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath, Boolean permitNull) +51
   System.Web.CachedPathData.GetConfigPathData(String configPath) +341
   System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +110
   System.Web.HttpContext.GetFilePathData() +36
   System.Web.HttpContext.GetConfigurationPathData() +26
   System.Web.Configuration.RuntimeConfig.GetConfig(HttpContext context) +43
   System.Web.Configuration.CustomErrorsSection.GetSettings(HttpContext context, Boolean canThrow) +41
   System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow, Boolean localExecute) +101
   System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) +383

我不确定这里出了什么问题。我需要以某种方式对输入进行编码吗?我需要在路由中指定不同的内容吗?

【问题讨论】:

    标签: asp.net-mvc encoding routing


    【解决方案1】:

    这是来自 Scott Hanselman 的 blog post,它应该会给你一些好的方向。

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2023-03-12
      • 2013-06-23
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      相关资源
      最近更新 更多