I switched my ASP.NET Web API from IIS-hosted to self-hosted. So far I had my images deployed in its own folder (and accessed them with HostingEnvironment.MapPath
). Obviously this folder doesn't exist in a self hosted environment. How can I handle images instead?
Asked
Active
Viewed 281 times
0

Dunken
- 8,481
- 7
- 54
- 87
-
You just want to access the images ? You *could* try - `System.Web.HttpContext.Current.Server.MapPath` – Yasser Shaikh Apr 09 '14 at 11:58
-
Current is null. But I think this is only part of the issue. The Images folder which I used to have (in my IIS installation) doesn't exist anymore... – Dunken Apr 09 '14 at 12:07
-
Hi, I'm still stuck with this issue... Any hints? – Dunken Apr 17 '14 at 07:57
1 Answers
0
OK, I figured it out. Here's what I did:
- set
Build Action
of each image asEmbedded Resource
- replace my
MapPath
with the following piece of code:
var resourcePath = "My.Namespace." + iconPath; //iconPath = subfolder.subfolder.file.ext
using (Stream imageStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourcePath))
{
...

Dunken
- 8,481
- 7
- 54
- 87