如何包含引号字符作为路由参数?获得"路径&QUOT非法字符;信息 [英] How to include quote characters as a route parameter? Getting "Illegal characters in path" message

查看:98
本文介绍了如何包含引号字符作为路由参数?获得"路径&QUOT非法字符;信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在所有页面上存在一个搜索框。用户可以输入文字,然后点击搜索,他们最终与他们所显示的结果的搜索页面上。

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".

与下面的堆栈跟踪:

[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

我不知道什么是错在这里..我需要带code输入不知何故?我需要指定一些路由不同?

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?

推荐答案

下面是一个<一个href=\"http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx\"相对=nofollow>斯科特Hanselman的博客帖子应该给你一些很好的方向。

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

这篇关于如何包含引号字符作为路由参数?获得&QUOT;路径&QUOT非法字符;信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆