Ampersand in MVC image URLs results in a potentially dangerous Request.Path

I have a bunch of images containing ampersands in their names. My site is built on Asp.net MVC3.

When I try to view an image using the URLs below my links and errors.

Example URL:

  • www.somesite.com/myimages/an-%26-image.jpg
  • www.somesite.com/myimages/an-&-image.jpg

Error: A potentially dangerous Request.Path value was found at the client (&).

Is there a problem around this problem? I really don’t want to disable validation or return to the request ValidationMode = "2.0", as I saw, as these are only problems with some images.

All images are in one folder (myimages), is it possible to stop scanning in a specific folder?

+6
source share
2 answers

I was able to fix this by making the following addition to Web.config

<httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,:,\,?" /> 

All that was removed was &amp; . I found out about this by narrowing which parts of this post should fix the problem.

+10
source

Having looked at the answer of this post , I think there is no way to allow these characters. Then only the solution is a mapping, try creating some data referencing the original image names in the database or XML. Create a controller and action to display images.

0
source

Source: https://habr.com/ru/post/887519/


All Articles