我需要创建生成一些图像并返回其路径的Web API。
我创建了使用以下方式保存的路径:
var resultPath = "Images/" + obiektId.ToString() + ".png";
var fullPath = HttpContext.Current.Server.MapPath("/" + resultPath);
并返回resultPath
。
问题是,我保留网站的虚拟目录是C:\\sites\siteA
而HttpContext.Current.Server.MapPath("/" + resultPath)
会返回C:\\inetpub\wwwroot\Images\123456.png
。然后我无法从10.0.0.106/siteA/Images/123456.png
加载图像。
如何将我的图像保存在基本虚拟目录中,而不是将其保存在wwwroot目录中?
答案 0 :(得分:0)
string resultPath = obiektId.ToString() + ".png";
string fullPath = System.Web.HttpContext.Current.Server.MapPath("~/Images"+ resultPath );