【发布时间】:2020-02-21 23:09:29
【问题描述】:
这三种获取wwwroot下图片路径的方法有什么区别?在我的情况下似乎所有工作都相同,但想了解它们之间是否存在任何其他具体情况的差异或使用一种方法的好处。
我使用此路径随后将图像加载到Bitmap MyBitmap 变量中以进行进一步处理。无论最终部署到 Windows、Linux 还是容器,都希望它具有环境弹性;本地或云端。
在 ASP.NET Core 3.0 中使用 Razor 页面。
public class QRCodeModel : PageModel
{
private readonly IHostEnvironment hostingEnvironment;
public QRCodeModel(IHostEnvironment environment)
{
this.hostingEnvironment = environment;
}
public void OnGet()
{
string TempPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", "Image1.png");
string TempPath1 = Path.Combine(Environment.CurrentDirectory, "wwwroot", "img", "Image1.png");
string TempPath2 = Path.Combine(hostingEnvironment.ContentRootPath, "wwwroot", "img", "Image1.png");
}
}
【问题讨论】: