I have static files folder:
And I followed Microsoft documentation to validate authorization and authentication:
My controller does not have [Authorize].
I need to Sign in to receive token, to show files only for authenticated users. I have JWT authentication btw.
What I'm doing wrong? Any help?
CodePudding user response:
You could find the explain in official document:
And the document also provide an alternative approach to serve files based on authorization is to: Store them outside of wwwroot and any directory accessible to the Static File Middleware. Serve them via an action method to which authorization is applied and return a FileResult object:
[Authorize]
public IActionResult BannerImage()
{
var filePath = Path.Combine(
_env.ContentRootPath, "MyStaticFiles", "images", "red-rose.jpg");
return PhysicalFile(filePath, "image/jpeg");
}