문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top