我的网址编码有什么问题

我的网址编码有什么问题

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

问题描述

限时删除!!

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

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



我认为它在%25(正斜杠)阻止。

我做错了什么? p>

- 编辑3 -

我尝试没有编码任何东西,但依赖于Url的默认编码。 RouteUrl()。

似乎这不会因为某些原因而编码/。

如果我自己首先编码,我最终会用编码的%252f 。这给我一个不好的要求,某些原因..
为什么?!



- 编辑2 -

我生成了URI的最后一部分,如下所示:


  1. 取id.toString

  2. 采取HttpUtility.UrlEncode(name)

  3. 获取HttpUtility.UrlEncode(代码)

  4. String.Format({0} - {1} - {2})与前面部分的值

  5. 将其作为参数添加到Url.RouteUrl()

之后,我的操作再次获取此参数,将其分解为 - 和HttpUtility.Decode()的值。



我这样做,因为最后两个参数是可选的,但功能参数。如果它们是在上一步中定义的,那么它们必须被携带到其他页面。

较少抽象:颜色可以有多个名称,但是如果用户按特定名称选择它,则应该保存在所有其他页面。



- 编辑1 -

它也看起来像HttpUtility.UrlEncode ()和Url.Encode()返回不同的结果:S



如果我不编码/,它将作为一个separator =>没有运气。
如果我用Url.Encode()对它进行编码,我最终会得到%2F => Code 400
如果我用HttpUtility.UrlEncode()对它进行编码,最终得到%25 => code 400



因为400甚至不让它通过asp.net-mvc,路由调试器是没有用的:(

解决方案

几天前我在那里,如果您可以在URL中接受不可读的路由值,请尝试以下操作:


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

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

I get error 400 (bad request).

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

--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?!

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

  1. Take the id.toString
  2. Take the HttpUtility.UrlEncode(name)
  3. Take the HttpUtility.UrlEncode(code)
  4. String.Format("{0}--{1}--{2}") with the values from the previous parts
  5. Add it as a parameter to Url.RouteUrl()

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

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.

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

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 400If I encode it with HttpUtility.UrlEncode() I end up with %25 => code 400

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

解决方案

I was there a couple of days ago. If you can accept unreadable route-values in the URL try this:URL-encoded slash in URL

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

1403页,肝出来的..

09-06 15:35