0

Server.MapPath is not showing my files with IIS 7.here is my simple code:

@{
    Layout = null;
}
@{
    string imgPath = Server.MapPath("~/Views/Home/anim.jpg");
}
<img src="@imgPath" />
malkovich
  • 1
  • 4

1 Answers1

0

The ~/Views/ folder is not allowed for direct access. You can put your static files under ~/Content/ folder and it should work.

I find a good thread discussing this:

https://stackoverflow.com/a/17949486/1982524

I recon it is a better solution to put your static files in another folder dedicated for static files. But if you want to store static files in Views folder, you can do it by modifying the web.config file.

In your view, you do not need to use Server.MapPath(...). You just reference your file with '~/Content/Images/whatever.jpg' in the view and it should work. You user server.MapPath only in your server code when you need the actual physical path of the file on disk.

Community
  • 1
  • 1
Yang Zhang
  • 4,540
  • 4
  • 37
  • 34