owin self-host with windows authentication - AllowAnonymous 不工作

owin self-host with windows authentication - AllowAnonymous not working

我已启用 Windows 身份验证

一切正常,只有一个小问题:这样做会使每个控制器方法都受到 windows 身份验证的保护。我认为没问题,只需在可以进行匿名访问的少数控制器方法上使用 [AllowAnonymous] 装饰器,但这行不通。

有没有办法让自托管不授权每个控制器上的每个方法?

您必须启用 Windows 身份验证 匿名身份验证。 documentation。实际上,您已告诉 Owin 要求 Windows 身份验证并禁止其他任何操作。

在您引用的代码中,您将更改为:

listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication 
                               | AuthenticationSchemes.Anonymous;