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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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).
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0