ASP.Net MVC - Images Not Displaying in Published Assembly

I am developing an ASP.Net MVC application and on my dev machine, the application works as expected and, more importantly, the images mentioned in the CSS file also render correctly.

However, when I publish this application on the test server, the web application is working fine, but the images are not displayed.

If I change the URL in IE when testing the output from the test server, the image is returned, which means that the file is there, but it just will not appear on the browse page under normal use of the site.

I also tried alternative servers, but the result is the same.

To confirm, here is a line from a CSS page linking to an image ...

background-image: url('/Content/Images/Logo/myLogo.jpg'); 

Any suggestions?

Greetings

Brett

+6
image asp.net-mvc
source share
4 answers

The URLs are incorrect, probably due to what you publish in a subfolder, and therefore they are no longer in the root of the server. I usually use Url.Content( "~/Content/Images/..." ) to create a URL instead of hard coding. Thus, he will take into account the routes when building the path.

Example:

  <img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" /> 
+19
source share

I had the same problem, but I found the reason why it forcibly turned on authentication in the "Content" folder.

When a user is not logged in yet, they are classified as anonymous authentication. In IIS7 (this is what I use, guessing that it is the same in IIS6), you need to open the authentication window in the function view. Then edit the anonymous authentication to use the application pool identifier or by default, just make sure the user has read permissions in this folder.

This fixed it for me, hope this works for you.

+3
source share

Possible relative paths are incorrect ... It is possible that they are incorrect for the CSS file itself. You can use FireBug to make sure CSS is loaded correctly, then you can view the image request, often in such situations you will see red (errors) elements. This can help localize the problem.

+1
source share

Why it needs to be done ... just finish my project, and now I need to go through all the changes in this format! All my javascript fail, all my images fail! For some strange reason, my css is just fine, but why the hell isn’t more documented !? Url.Content does not even appear under intellisense! ASP MVC just lost meaning in my scope of love.

- very frustrated encoder

0
source share

All Articles