【发布时间】:2021-01-17 20:16:54
【问题描述】:
我在 wwwroot 中放置了几个具有静态内容的文件夹。 对于某些文件夹,我需要该用户经过身份验证才能查看这些文件夹。
为此,我在 Startup 中添加了如下代码。
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = ctx=>
{
if(!ctx.Context.User.Identity.IsAuthenticated && ctx.Context.Request.Path.Value("admin/manuals"))
{
ctx.Context.Response.Redirect("/");
}
}
}
虽然我已通过身份验证,但我总是得到 isAuthenticated 错误。 为什么我也得到这个..
还有什么是处理这种情况的更好方法。
【问题讨论】:
-
嗨@Codeone,如果我的回答对你有帮助,你能接受吗?它也可以帮助其他人。
标签: c# asp.net-core asp.net-core-mvc asp.net-authentication