What is wrong with my url encoding?

In my asp.net mpc 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 is blocking at% 25 (slash).
What am I doing wrong?

- EDIT 3 -
I tried not to encode anything at all, but rather relied on the default encoding Url.RouteUrl ().
It seems that for some reason this does not encode "/".
If I encrypt it first, I get code with double value% 252f. For some reason this gives me a bad request .. Why?

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

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

After that, my action again receives this parameter, splits it into - and HttpUtility.Decode () values ​​back.

I do it this way because the last two parameters are optional but functional parameters. If they are defined in the previous step, they must be transferred to other pages.
Less abstract: a color can have several names, but if the user selected it by a specific name, it should be stored on all other pages.

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

If I don't encode "/", it acts as a delimiter => no luck. If I encode it using Url.Encode (), I get% 2F => Code 400 If I encode it using HttpUtility.UrlEncode (), I get% 25 => Code 400

Since 400 doesn't even skip it to asp.net-mvc, the route debugger is useless :(

+4
source share
6 answers

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

+3
source

%25 actually encoded "%", so %252f encoded "% 2f".

%2f (encoded "/") is not allowed in the URL unless you explicitly allow it in the web server configuration.

+1
source

I did not look at the encoding too much, but note that if it should be somewhere (or in some way), then POST would be more appropriate. If the text on the right actually represents data with ID 351702 (vanity vanity very similar to /665354/whats-wrong-with-my-url-encoding ), then you should humanize the text. Since the spaces have been removed from the foregoing. It also often occurs as a separate level on the route, which is simply discarded.

Generally, MVC URLs should be understandable.

0
source

You cannot use a slash as a value in a URL. Here is a good article on creating a browser and SEO friendly URL => http://www.dominicpettifer.co.uk/displayBlog.aspx?id=34

[Edit] Whenever you create a route, you associate it with a URL pattern (the default pattern is {controller} / {action} / {id}). And in this url template, you should use a slash to separate different tokens. Hope that helps

0
source

All Articles