asp.net-mvc - 声明授权管理器问题

标签 asp.net-mvc authorization wif

我正在使用自定义的 ClaimsAuthorizationManager 在 MVC 中进行授权,但遇到了问题。

  • 即使我只是在 CheckAccess 方法中返回“true”,所有 文件/图像因 500 运行时错误而被阻止,因为:

Exception information: Exception type: NotSupportedException Exception message: ID1075: The ClaimsAuthorizationModule cannot be used without the current principal (HttpContext.Current.User) being a ClaimsPrincipal. at System.IdentityModel.Services.ClaimsAuthorizationModule.Authorize()

我不会在申请早期更改有关现任校长的任何内容...有什么想法吗?我很困惑,搜索该错误没有发现任何结果......

<小时/>
<system.webServer>    
    <modules>      
      ...
      <add name="ClaimsAuthorizationModule" type="System.IdentityModel.Services.ClaimsAuthorizationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </modules>
</system.webServer>


  <system.identityModel>
    <identityConfiguration>
      <claimsAuthorizationManager type="NamespaceFun.CustomAuthorizationManager, NamespaceFun" >
    <policy resource="http://localhost:52606/" action="GET">
    </policy>
      </claimsAuthorizationManager>
      ...
    </identityConfiguration>
   </system.identityModel>


public class CustomAuthorizationManager : ClaimsAuthorizationManager
{      
    public override bool CheckAccess(AuthorizationContext context)
    {   
        return true;            
    }       
}

最佳答案

我也遇到了同样的问题,所以我将我的 web.config 与 WIF 书中的 web.config 进行了比较,结果发现我在 add 元素的末尾缺少 preCondition="managementHandler" ,看来你也错过了。

MSDN example 中似乎也缺少它。 。

正确方法:

<add name="ClaimsAuthorizationModule" 
     type="System.IdentityModel.Services.ClaimsAuthorizationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     preCondition="managedHandler" />

关于asp.net-mvc - 声明授权管理器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15482663/

相关文章:

asp.net-mvc - 你的 Controller 在 asp.net-mvc 中应该有多大

asp.net-mvc - IdentityServer4 用户管理与单独的 MVC 客户端 (AspNetIdentity)

c# - 将 MVC4 站点部署到 Azure 会导致 ExtensionAttribute 异常

Apache Shiro - 用于身份验证的 LDAP 和用于授权的 Properties/Ini

asp.net - 将 ADFS token 传递给服务

c# - 使用 WIF 在 Asp.Net 4.5 上自定义身份验证

asp.net-mvc - ASP.NET MVC - 强类型 View 模型,它属于哪里?

ruby-on-rails - 通过 id 检查用户权限的最佳方法?

asp.net-core - Blazor WASM 中的授权 - 策略不起作用

wcf - 如何在WCF和WIF中使用JWT token ?