5

I have 2 image files in my App_Data directory and I want to show them in my view like this:

@foreach (var media in Model)
{
     <div class="col-lg-3 col-md-4 col-xs-6 thumb">
         <a class="thumbnail"><img src="@Url.Content("~/App_Data/uploads/" + @media.URL)" alt="image" /></a>
      </div>
}

When I check the link in the browser I get this :

<img src="/App_Data/uploads/Warnings.png" alt="image">

It says he can't find the image. How can I set the correct link?

nielsv
  • 6,540
  • 35
  • 111
  • 215
  • 1
    Check if you had a web.config configured in App_Data folder, this can cause many problems. Anyways you should not store images in this folder. – Roberto Conte Rosito Dec 19 '13 at 17:30
  • 1
    @RobertoConteRosito is right. You really shouldn't. http://stackoverflow.com/questions/1519790/images-that-are-in-app-data-folder-not-shown-in-browser – LiverpoolsNumber9 Dec 19 '13 at 17:31

1 Answers1

11

The App_Data folder is a special .NET "system" folder in which IIS is configured to not allow the contents of that folder to be visible to web users. Create a different folder to store your images as you really should not allow App_Data to be web visible (if you can even change the setting).

From iis.net:

For example, on Web servers that are hosting ASP.NET content, IIS 7 blocks several of the ASP.NET-related paths for you; Web.config, bin, App_Code, etc. Blocking these URL segments reduce the chance of an attacker being able to exploit these URLs for information.

Tommy
  • 39,592
  • 10
  • 90
  • 121