我有一个Excel电子表格集合,我希望在我的ASP.NET 5 webapp应用程序中仅向授权用户提供这些表格。
非常感谢!
发布于 2016-04-22 01:06:31
发布于 2018-12-19 14:39:11
对于检索文件时的身份验证检查:
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = (context) =>
{
if (!context.Context.User.Identity.IsAuthenticated && context.Context.Request.Path.StartsWithSegments("/excelfiles"))
{
throw new Exception("Not authenticated");
}
}
});
发布于 2017-05-22 18:08:29
在.net内核中,创建一个与wwwroot相同级别的专用目录www,并使用以下代码:
public HomeController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[Authorize(Roles = "SomeRole")]
public IActionResult Performance()
{
return PhysicalFile(Path.Combine(_hostingEnvironment.ContentRootPath,
"www", "MyStaticFile.pdf"), "application/pdf");
}
基于以下答案(针对.netCore):static file authorization
https://stackoverflow.com/questions/36775942
复制相似问题