I intend to return a static html page from my controller action. The html page is part of my project / bundle. I have the following code which works when run locally (localhost), but when on Azure, it fails. I don't have access to the Azure instance at the moment so I can not debug it or turn on Development mode for detailed errors etc. Please excuse the naiveness, what is the issue with the following code:
public IActionResult PrivacyPolicy()
{
//_hostingEnvironment is an instance of IHostEnvironment
var staticPage = PhysicalFile(System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Views/Home/PrivacyPolicy.html"), "text/html");
return staticPage;
}
If you have access problems you can simply read the file and then just return its content:
return Content(File.ReadAllText("somefile.html"));
Darin Dimitrov also answered a question about this, that uses a different approach. please also have a look at that:
How do you request static .html files under the ~/Views folder in ASP.NET MVC?
Also as Darin says, you may want to put your static file in a different directory than Views
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With