0

Possible Duplicate:
Images in CSS not showing in ASP.NET MVC

I have already asked this but didn't receive an answer that fixed it. I'm asking again because I have tried everything I can think of and am absolutely stuck. My previous question was here: CSS images not showing in ASP.NET MVC

I have an ASP.NET MVC application with images in an ~/image/ directory. When I run it in development, the images show fine. When published, they do not show at all. I don't think it is a reference path issue because I've tried every combination of ../, ./, ~/, etc. I can think of. Neither css references, <img> or <asp:Image> tags work and all have the same problem. I've tried editing windows security on the image and all parent folders to no avail.

When I mouse over the image path in firebug, the image preview box just spins as though the image is found but can't load.

The very strange thing is that when I try to go to the image directly (www.web.com/images/image.png), I am redirected to the default log in page. The default account controller that ASP.NET MVC puts in projects is in my app, but I have not implemented any log in controls yet. So I think it's an issue with authentication. Or perhaps it is an IIS issue?

I appreciate any help you can give. I have been stuck on this for almost a week and may have to abandon images all together I can't get this sorted.

Community
  • 1
  • 1
Ross
  • 131
  • 2
  • 2
  • 12

5 Answers5

5

The redirect to a logon page is a usual indicator that your IIS security is set to force authentication before displaying the contents of the specified directory. The images subdirectory is one of those usually permitted to be visible even by unauthenticated users.

Add this to your web.config file under the <configuration> element to allow unfettered access to the contents of that directory:

<location path="images">
  <system.web>
    <authorization>
      <allow users="?"/>
    </authorization>
  </system.web>
</location>
Tahbaza
  • 9,486
  • 2
  • 26
  • 39
  • Thanks for the reply, but I added this and still nothing. Is there a way to verify the image visibility setting in IIS? – Ross Apr 09 '11 at 05:20
  • 1
    I reread your other question on this same topic. In there you reference an **images** (with an s) subdirectory. If the subdirectory is plural you'll need to make the path portion of the location tag plural also (I've edited the answer to match). Also, to rule out a CSS path issue try this in your css file: `url('../images/bsb_header2.png') ` – Tahbaza Apr 09 '11 at 14:25
  • @Tahbaza - I know this thread is almost 7 years old, but you solved a problem I've been having for an hour or more now! – KentGeek Nov 23 '17 at 16:31
4

Check the path in firebug. Is it correct?

Are you using the helper to generate the URL? Something like:

<img src='<%= Url.Content("~/images/image.png")' />
rcravens
  • 8,320
  • 2
  • 33
  • 26
2

I FINALLY figured it out. The image file in question was encrypted. Right click the image file -> properties -> advanced button on general tab -> uncheck "Encrypt contents to secure data" -> OK -> OK.

The tip off finally came when I noticed the file name was green in windows explorer. I see green file names all the time with no problems so I didn't think anything of it. Then I noticed it was the only green file in the entire web app folder. Put 2 and 2 together and it worked instantly. Thanks everyone for your help.

Ross
  • 131
  • 2
  • 2
  • 12
0

I reread and see that you are using iis instead of casini. Does it work in casino. If it does, then we are dealing with an iis config issue. Sometimes you need to run aspnet_regiis.exe to register asp.net with iis. Seems like a long shot since the other parts of the page are rendering. Worth a try. Here is a link with some additional info http://www.devx.com/vb2themax/Tip/18849.

rcravens
  • 8,320
  • 2
  • 33
  • 26
  • Thank you! I installed CassiniDev and images load correctly through it, so now I know for sure it's an IIS issue. I will try registering asp.net with IIS as you suggest and report back, but at least I have something to fall back on now. – Ross Apr 09 '11 at 17:51
  • ran aspnet_regiis.exe; same issue. Falling back on CassiniDev for now, but I definitely know it's an IIS issue now, thanks. – Ross Apr 09 '11 at 18:10
0

Just for kicks, put some images under a different folder and try and see if you can hit them without having to authenticate, it would be good if you posted your web.config

BlackTigerX
  • 6,006
  • 7
  • 38
  • 48