开发者

How to include quote characters as a route parameter? Getting "Illegal characters in path" message

开发者 https://www.devze.com 2023-01-20 08:56 出处:网络
I have a search box that exists on all pages. The user can enter text, and click search and they end up on the Search page with the results displayed for them.

I have a search box that exists on all pages. The user can enter text, and click search and they end up on the Search page with the results displayed for them.

When search is clicked, the form containing the textbox is sent off to the following route:

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

this works. But if I put quotes around the string,

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

This fails with the error message "Illegal characters in path".

with the following stack trace:

[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

I'm not sure what's wrong here.. Do I need to encode the input somehow? Do I need to specify something different in the routing?


Here's a blog post from Scott Hanselman that should give you some good directions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号