在 ASP.NET/IIS 的 url 中使用冒号 (:) [英] Using a colon (:) in a url with ASP.NET/IIS

查看:18
本文介绍了在 ASP.NET/IIS 的 url 中使用冒号 (:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 ASP.NET MVC 中实现自定义控制器,真的希望能够在 url 中使用冒号,以便我可以识别类/列名称及其值,例如所以:

I'm implementing a custom controller in ASP.NET MVC and really want to be able to use a colon in the urls, so that I can identify class/column names and their values, like so:

http://example.com/user:chaiguy

...但显然 ASP.NET 或 IIS 不允许在 url 中使用冒号.我做了一些挖掘,显然它被认为是一个安全问题,但是,我正在使用 MVC 并且正在手动处理 所有 url 路径(只是将它们视为字符串),而不是将它们与文件系统相关联,所以我很确定这不适用.

...but apparently ASP.NET or IIS doesn't allow colons in urls. I did some digging and apparently it's considered a security issue, but, I'm using MVC and am handling all url paths manually (just treating them as strings), and not relating them to the file system, so I'm pretty sure this doesn't apply.

我也听说过一些关于实现自定义 Http 处理程序之类的话题.

I also heard some talk about implementing a custom Http handler or something.

任何想法或想法将不胜感激.

Any thoughts or ideas would be much appreciated.

呃……为什么?说真的,为什么要打破标准?– 兰多夫

Er.... why? Seriously, why break standards? – Randolpho

...

那么,我建议您调查构建 Web 服务.WCF 是一种很好的技术,它可以很好地托管在 IIS 中.

I suggest, then, that you investigate building a web service. WCF is a nice technology for that, and it hosts well in IIS.

我碰巧喜欢 url,而 WCF 对我来说太复杂了.我希望它像 REST 一样与 url 兼容,但不仅可以导航层次结构,还可以处理布局合理的事情.我对/users/chaiguy 的问题是它正在解释没有的层次结构:在我的系统中,用户"是一个类,它不是一个文件夹.user:chaiguy 表示值为chaiguy"的用户类的实例,它是一个单一的实体,有可能拥有子实体.例如:

I happen to like urls, and WCF is way too complicated for my purposes. I want it to be url-compatible, like REST, but capable of more than just navigating hierarchies, or doing well laid-out things. The problem I have with /users/chaiguy is that it is interpreting hierarchy where there is none: in my system "user" is a class, it's not a folder. user:chaiguy means the instance of the user class with the value of "chaiguy", and that is a single entity, that has the potential of having child-entities. So for example:

/user:chaiguy/name

...我想显示该实体的名称.如果我用你的方法这样做,它看起来像这样:

...I would like to display the name of that entity. If I did this with your method, it would look like this:

/users/chaiguy/name

问题是你怎么知道类是什么,值是什么?可以理解为

The problem is how do you know what's the class and what's the value? It could be interpreted as

/users/chaiguy:name

在我的系统中,这是没有意义的.看到我在说什么了吗?举一个稍微复杂一点的例子,假设我们想从多个实例中选择用户实体的一个子实体.因此,用户可能有多个电子邮件地址.要选择一个,我们可以使用:

in my system, and that doesn't make sense. See what I'm getting at? To give a slightly more complicated example, suppose we want to select a child of the user entity out of multiple instances. So a user might have several email addresses. To select one, we might use:

/user:chaiguy/email:me@here.com/

所以它实际上是递归的.它不是一个文件路径,它更像是一个 XPath(或者可能类似于基于我所知的 jQuery).也就是说,它更像是一个动态评估的查询选择,而不是一个硬连线的文件路径.它在服务器上进行评估.

So it is in fact recursive. It's not a file path, it's more like an XPath (or maybe similar to jQuery based on what little I know of it yet). That is, it's more of a dynamically-evaluated query selection than a hardwired file path. It gets evaluated on the server.

毫无疑问,我不是在这里构建典型的网站甚至网络服务.

Make no mistake, I'm not building a typical web site or even web service here.

推荐答案

更改 web.config 中 httpRuntimerequestPathInvalidCharacters 属性:

Change the requestPathInvalidCharacters attribute of httpRuntime in web.config:

<httpRuntime maxRequestLength="20480" requestValidationMode="2.0" requestPathInvalidCharacters="" maxQueryStringLength="20480" />

并且 ASP.NET 不应再阻止请求路径中的冒号.

and ASP.NET should no longer block colons from your request path.

这篇关于在 ASP.NET/IIS 的 url 中使用冒号 (:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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