Pregunta

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?

¿Fue útil?

Solución

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)) { ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top