有什么毛病我的URL编码? [英] What's wrong with my url encoding?

查看:277
本文介绍了有什么毛病我的URL编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net mvc的应用程序,我创建了以下链接:

In my asp.net mvc application I created the following link:

http://localhost:2689/en/Formula.mvc/351702++LYS+GRONN+5G+9%252f2++fds  

我得到错误400(错误的请求)。

I get error 400 (bad request).

我觉得它会阻止在25%(正斜杠)。
我究竟做错了什么?

I think it blocks at the %25 (forward slash).
What am I doing wrong?

- 编辑3 -
我试过在所有编码什么,而是依赖于Url.RouteUrl()的默认编码。
看来,这并不EN code中的/出于某种原因。
如果我的连接code我自己第一次,我结束了与doubel EN codeD%252F。这给了我一个错误的请求由于某种原因.. 为什么呢?!

--EDIT 3--
I tried not encoding anything at all but rather rely on the default encoding of Url.RouteUrl().
It seems that this doesn't encode the "/" for some reason.
If I encode it myself first, I end up with the doubel encoded %252f. This gives me a bad request for some reason.. Why?!

- 编辑2 -
我所产生的URI的最后部分如下:

--EDIT 2--
I generated the last part of the URI as follows:

  1. 乘坐id.toString
  2. 乘坐HttpUtility.UrlEn code(名称)
  3. 乘坐HttpUtility.UrlEn code(code)
  4. 的String.Format({0} - {1} - {2})从previous部分的值
  5. 添加它作为参数传递给Url.RouteUrl()

在我的行动再次获得这个参数,将其分解为 - 。和HttpUtility.De code()的值返回

After that my action gets this parameter again, splits it at -- and HttpUtility.Decode() the values back.

我做这种方式,因为最后两个参数是可选的,但功能参数。如果他们是在previous步骤中定义的,它们必须跟着其他页面进行。
少抽象:一个颜色可以有多个名称,但是,如果用户选择它由特定的名称,它应保持在整个所有其他网页

I do it this way because the two last parameters are optional, but functional parameters. IF they are defined in a previous step, they have to be carried along to the other pages.
Less abstract: A color can have multiple names, but if a user selected it by a particular name, it should be kept throughout all the other pages.

- 编辑1 -
它也像HttpUtility.UrlEn code()和Url.En code()返回不同的结果:•

--EDIT 1--
It also looks like HttpUtility.UrlEncode() and Url.Encode() return different results :S

如果我不连接code中的/,它作为一个分隔符=>没有运气。 如果我的连接code用Url.En code()我最终%2F => code 400 如果我的连接code用HttpUtility.UrlEn code()我结束了%25 => code 400

If I don't encode the "/", it acts as a separator=>no luck there. If I encode it with Url.Encode() I end up with %2F => Code 400 If I encode it with HttpUtility.UrlEncode() I end up with %25 => code 400

由于400甚至没有让它通过对asp.net-MVC,路线调试器是没有用的:(

Because 400 doesn't even let it through to asp.net-mvc, the route debugger is of no use :(

推荐答案

我一个前几天在那里。如果你能接受在URL中不可读的路线值试试这个: <一href="http://stackoverflow.com/questions/591694/url-en$c$cd-slash-in-url">http://stackoverflow.com/questions/591694/url-en$c$cd-slash-in-url

I was there a couple of days ago. If you can accept unreadable route-values in the URL try this: http://stackoverflow.com/questions/591694/url-encoded-slash-in-url

这篇关于有什么毛病我的URL编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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