Question

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?

Was it helpful?

Solution

OK, I figured it out. Here's what I did:

  • set Build Action of each image as Embedded 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)) { ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top