I have same images in Content and Views folders. I am trying to display images as below:
<img src="~/Content/Images/download.png" alt="Content folder" />
<br />
<br />
<img src="~/Views/Home/download.png" alt="Views folder" />
<br />
The image in Content folder displays successfully but the one in Views folder doesn't display and gives below error:
Failed to load resource: the server responded with a status of 404 (Not Found)
But actually, the resource is there. Here are my folders:
Could you please tell me which point I am doing wrong? I am using MVC 5 with razor engine and Visual Studio 2015 community edition.
Unless you changed the default configuration, folder Views
contains file Web.config
that has settings for restricting access to files in this folder:
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
So you can either remove this handler (which is not recommended for security purposes), or move your static files to some other folder, e.g. Content
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With