【发布时间】:2021-03-20 17:01:19
【问题描述】:
我默认使用 cookie 身份验证方案。 我有一个特定的区域,我想在其中允许额外的身份验证方案,否则,所有现有的策略都应该保持不变。
我已尝试将 AuthoriztionFilter 添加到 IPageHandlerModelConvention/IControllerModelConvention:
public class AreaFiltersConvention : IPageHandlerModelConvention
{
public string[] Areas { get; set; }
public void Apply(PageHandlerModel model)
{
if (this.Areas.Contains(model.Page.AreaName))
{
model.Page.Filters.Add(new AuthorizeFilter("AllowBasicAuthPolicy"));
}
}
我有两个问题:
-
PageHandlerModel.Page为空,所以无法添加 AuthorizeFilter。 -
据我所知,我只能在需要特定策略时使用它。我在 OR 条件下苦苦挣扎。
services.AddAuthorization(options => { options.AddPolicy("AllowBasicAuthPolicy", policy => { policy.AddAuthenticationSchemes("Basic"); // this breaks existing policies policy.RequireAuthenticatedUser(); }); });
【问题讨论】:
标签: c# asp.net-core authorization .net-5