I have a collection of Excel spreadsheets that I\'d like to serve in my ASP.NET 5 webapp only to authorized users.
in .net core create a dedicated directory www in same level as wwwroot, and use the following code:
public HomeController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[Authorize(Roles = "SomeRole")]
public IActionResult Performance()
{
return PhysicalFile(Path.Combine(_hostingEnvironment.ContentRootPath,
"www", "MyStaticFile.pdf"), "application/pdf");
}
Based on the following answer (for .netCore): static file authorization