Image not found in ASP.NET MVC 3 in IIS7

I searched for a similar thread and did not find a solution. My problem:

  • I created an asp mvc 3 webpage in visual studio 2010
  • I added images to Content / Images that will be used on one page
  • I added a folder called swf containing the flash file for another page

Everything works when I run it on the local host, .css layouts and all that.

Problem: When I put it in IIS

  • .css does not appear on SOME pages, not all of them
  • The flash object does not appear, I suspect that it does not find it or something like that.

I read that this is a common problem, but did not find how to solve it, any help was appreciated.

Additional Information

Here are snippets of code in different parts

@{ Layout = "~/Views/Shared/_Layout_Green.cshtml"; } <link rel="Stylesheet" type="text/css" href="@Url.Content("~/Content/history.css")" /> <script type="text/javascript" src="@Url.Content("~/Scripts/history.js")"></script> <script type="text/javascript" src="@Url.Content("~/Scripts/swfobject.js")"></script> <script type="text/javascript"> var swfVersionStr = "10.0.0"; var xiSwfUrlStr = "/swf/playerProductInstall.swf"; swfobject.embedSWF("/swf/QrCodeReader.swf", "flashContent", "350px", "350px", "10.0.0", xiSwfUrlStr, flashvars, params, attributes); swfobject.createCSS("#flashContent", "display:block;text-align:left;"); <li><img src="/Content/Images/flower.png" width="700" height="300" alt="" /></li> 
+4
source share
3 answers

Try using the @Url.Content syntax for the paths you use in your javascript. This ensures that paths are created correctly no matter how your virtual directories are configured.

 var xiSwfUrlStr = '@Url.Content("~/swf/playerProductInstall.swf")'; swfobject.embedSWF('@Url.Content("~/swf/QrCodeReader.swf")', "flashContent", "350px", "350px", "10.0.0", xiSwfUrlStr, flashvars, params, attributes); <li><img src='@Url.Content("~/Content/Images/flower.png")' width="700" height="300" alt="" /></li> 
+6
source

Try using:

 <%= ResolveUrl("~/Content/Images/flower.png") %> 

That must do it.

0
source

fyi - download the violinist, and you can easily request uri and your 404 errors.

0
source

All Articles