我有一个 ASP.NET Core 1.0 项目正在运行。当我将 ClaimsPrinciplePermission 属性添加到我的操作方法时,我在导航到具有该属性的任何操作方法时收到以下错误。



这是内部异常



这是我的 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <configSections>
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection,  System.IdentityModel.Services, Version=4.0.0.0,  Culture=neutral, PublicKeyToken=B77A5C561934E089" />
  </configSections>

  <system.identityModel.services>
    <federationConfiguration>
      <cookieHandler requireSsl="false" />
    </federationConfiguration>
  </system.identityModel.services>
  <system.identityModel>
    <identityConfiguration>
      <claimsAuthorizationManager type="wApp.ClaimManager, wApp" />
    </identityConfiguration>
  </system.identityModel>

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>




</configuration>

如您所见,我已经添加了所有必需的部分。相同的代码和配置在我的 MVC 5 项目和我的 Web Api 项目中运行良好。在 Asp.Net Core 项目中有什么不同的事情要做吗?

我还在 Core 1.0 MVC 项目中添加了所需的 DLL 引用,并在 Core 1.0 MVC 项目下的 App.config 文件中复制了相同的配置部分。仍然得到同样的错误。

我错过了什么?

最佳答案

ClaimsPrincipalPermission 和 WIF/System.IdentityModel 根本不是 .NET Core 的一部分。我很惊讶甚至可以编译。

从评论看来,您正在解析 JWT,大概是使用 JWT 不记名 token 中间件。

因此,ASP.NET Core 中的所有身份都是 ClaimsIdentities。您可以选择 Simple claims based checks ,或者更全面地选择 code expressed policies ,这提供了更大的灵活性。

关于asp.net-core - 在 web.config 中未检测到 system.identityModel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40046321/

10-16 18:13