Reputation: 111
I have a view which looks like this {{img src="/Scenario/Status/id" alt="status" /}}
(replace <> these {} above )
and this is the code in action of the controller
public ActionResult Status(int? id)
{
// Calculate the status
int no = new Random().Next(0, 2);
string file = "green.jpg";
if (no == 0)
{
file = "red.jpg";
}
else if (no == 1)
{
file = "yellow.jpg";
}
else if (no == 2)
{
file = "green.jpg";
}
var path = Server.MapPath("/Content/images/");
var filePath = path + file;
return new FileContentResult(System.IO.File.ReadAllBytes(filePath), "image/jpeg");
}
This works just fine when i run on visualstudio. But when i deploy it to local IIS, I dont see these images. I checked that the "StaticContent" option is checked in Windows Features under IIS and also that the MIME type is enabled on IIS. I also checked that the *.jpg files are present under "inetpub" folder of my app after I publish from visual studio. Since i'm using virtual path for images and not hardcofing the filenames , it should work...
I just tried this
{{img src="../Content/Images/Green.jpg" alt="status" /}} and that works too.. :(
What else could be wrong?
Upvotes: 2
Views: 4743
Reputation: 111
Found the solution for displaying images in an app hosted in a sub folder unde root site on IIS
This worked..
img src = "<%= Url.Content("~/Home/GetRainfallChart") %>" alt="chart"
Upvotes: 2
Reputation: 2239
It is deployed to a virtual directory C:\inetpub\wwwroot\testsite.... Is that th eproblrm
Upvotes: 0
Reputation: 6009
A quick way to gain more insight into the problem would be to set a breakpoint in the Application_Error
method of the global.asax, and see what exception is being raised when the request for the image comes in.
If you've deployed under a virtual directory in IIS, You'll need to use Server.MapPath("~/Content/images/")
Where Asp.Net will replace ~
with the application root.
Upvotes: 2