3

In my ASP.NET MVC application, I am referencing background images via CSS. When I run it in the dev environment, they show up fine. But when I deploy it (using IIS 7.5) the images do not load at all. I have tried every combination of relative paths and background/background-image CSS tags, but nothing works. Here is my file structure and CSS:

File structrue:

Content  
    CSS file  
images  
    image.png  

CSS:

background-image: url(/images/bsb_header2.png);

I have also tried ../images/bsb_header2.png and ../../images/bsb_header2.png to no avail.

What is really strange is when I try to go to the image directly (i.e. www.website.com/images/image.png), I am redirected to a login page. Perhaps there is some access or security setting I'm missing? I haven't done anything with login controls yet (the default account view and controller are in my project but I haven't done anything with them yet) and I can view all my other pages just fine.

Update: I FINALLY figured it out. The image file in question was encrypted. Right click the image file and navigate to properties, click the advanced button on the general tab, uncheck "Encrypt contents to secure data", click 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 two and two together and it worked instantly. Thanks everyone for your help.

alex
  • 6,818
  • 9
  • 52
  • 103
Ross
  • 131
  • 2
  • 2
  • 12

7 Answers7

4

Please Add two users IUSR, IIS_IUSRS to the publish folder and assign permission for them to read & execute

RAY
  • 2,201
  • 2
  • 19
  • 18
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
1

in css set "display: block"

.searchbtn
{
    margin-top:-15px;
    background-image:url(../images/icons/search.png);
    background-repeat:no-repeat;
    width:18px;
    height:18px;
    display: block;
}
Balachandar P
  • 371
  • 2
  • 4
1

Is it possible that IIS 7.5 was not installed correctly?

If you go to Turn Windows Features on or off - under:

Internet Information Services / World Wide Web Services / Common Http Features

there is a Static Content checkbox

is it checked?

see this link for screen-shot.

Nicholas Murray
  • 13,305
  • 14
  • 65
  • 84
0

From your description, it appears as if the Request for the .png is getting routed to the ASP.NET/MVC engine instead of being served up by IIS.

Is it possible that the routing rules in the Global.asax are picking .png files? (I know this doesn't explain why it works in your dev environment).

Does it work if you add a ignoreRoute for .png files at the beginning of your route list in Global.asax? Something like below...

 routes.IgnoreRoute("{resource}.png");
Naraen
  • 3,240
  • 2
  • 22
  • 20
  • Thanks, but unfortunately this didn't work. I'm fairly new to IIS; is there a setting in IIS that I have to set to have it serve images? – Ross Apr 07 '11 at 04:53
0

The URL should be relative!

background-image: url(images/bsb_header2.png)
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • "I have also tried ../images/bsb_header2.png and ../../images/bsb_header2.png to no avail." - which are both relative. – Michael Shimmins Apr 07 '11 at 04:18
  • Thanks but this didn't work. I think the problem is something deeper. As I mentioned, I can't even surf directly to the image. I'm prompted to log in when I do. – Ross Apr 07 '11 at 04:55
0

Had the same issue and finally found a solution.

  • In IIS open "Authorization Rules".
  • If there is nothing there, click "Add Allow Rule"
  • Choose "All Users" and hit OK
BrianM
  • 538
  • 1
  • 3
  • 8