我将ASP.NET Web API从IIS托管切换为自托管。到目前为止,我已将我的图像部署在自己的文件夹中(并使用HostingEnvironment.MapPath
访问它们)。显然,此文件夹不存在于自托管环境中。我该如何处理图像呢?
答案 0 :(得分:0)
好的,我明白了。这就是我的所作所为:
Build Action
设置为Embedded Resource
MapPath
: var resourcePath = "My.Namespace." + iconPath; //iconPath = subfolder.subfolder.file.ext
using (Stream imageStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourcePath))
{
...