C# 从wwwroot下载html文件时,始终显示未找到错误
我正在尝试下载一个放置在wwwroot中的.html文件 这就是功能:C# 从wwwroot下载html文件时,始终显示未找到错误,c#,asp.net,asp.net-mvc,asp.net-core,C#,Asp.net,Asp.net Mvc,Asp.net Core,我正在尝试下载一个放置在wwwroot中的.html文件 这就是功能: public FileResult Download() { var file = Path.Combine(System.IO.Directory.GetCurrentDirectory(),"EmailTemplate","base.html"); var x = System.IO.File.Exists(file); var result = File(file, MediaTypeNames
public FileResult Download()
{
var file = Path.Combine(System.IO.Directory.GetCurrentDirectory(),"EmailTemplate","base.html");
var x = System.IO.File.Exists(file);
var result = File(file, MediaTypeNames.Text.Html);
return result;
}
我试图检查文件是否存在,但返回false。file变量显示文件的路径,该路径为:
wwwroot\EmailTemplate\base.html
我不确定我还需要做什么
编辑:
这是我添加到Startup.cs中的内容。请确保您有
app.UseStaticFiles()在启动
文件中的配置
方法中的code>
在控制器中,您可以插入IHostingEnvironment
接口,并使用它检索wwwroot
路径,如:
_hostingEnvironment.WebRootPath;
确保您有app.UseStaticFiles()在启动
文件中的配置
方法中的code>
在控制器中,您可以插入IHostingEnvironment
接口,并使用它检索wwwroot
路径,如:
_hostingEnvironment.WebRootPath;
确保您有app.UseStaticFiles()在启动
文件中的配置
方法中的code>。在控制器中,您可以插入IHostingEnvironment
接口,并使用它检索wwwroot
路径,如:\u hostingenEnvironment.WebRootPath代码>。谢谢!你能把你的答案定下来吗?它帮助了我。确保你有app.UseStaticFiles()在启动
文件中的配置
方法中的code>。在控制器中,您可以插入IHostingEnvironment
接口,并使用它检索wwwroot
路径,如:\u hostingenEnvironment.WebRootPath代码>。谢谢!你能把你的答案定下来吗?它帮助了我。