【问题标题】:system.identityModel not detected in web.config在 web.config 中未检测到 system.identityModel
【发布时间】:2017-02-24 01:44:05
【问题描述】:

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

“System.InvalidOperationException”类型的异常发生在 System.IdentityModel.Services.dll 但未在用户代码中处理

附加信息:ID7024:ClaimsPrincipalPermission 的使用 属性已尝试,可能没有 配置部分定义,见内部 细节例外。还要确保 ClaimsAuthorizationManager 元素在该部分下定义。

这是内部异常

ID7027:无法加载身份配置,因为没有 已找到配置部分。

这是我的 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 文件中复制了相同的配置部分。仍然得到同样的错误。

我错过了什么?

【问题讨论】:

  • 如何在启动类中配置身份? .Net Core 不读取 web.config 文件
  • AFAIK,ASP .NET Core 依赖project.json 作为其配置文件,既没有使用web.config 也没有使用app.config 文件。将所有IdentityModel 引用添加到项目文件并确保相关依赖项可用。
  • @TetsuyaYamamoto 你的意思是 appsettings.json?我不知道如何将配置文件中的configsections转换为json格式。我找不到它的例子。如果 web.config 不起作用,那为什么新建 aspnetcore 项目时会在项目中提供呢?
  • @aguafrommars 你有在启动类中配置身份的例子吗?也是 .NET Core 需要的配置文件的示例?
  • 这可能会有所帮助:docs.asp.net/en/latest/fundamentals/configuration.htmlappsettings.jsonproject.json 内容在 ASP .NET Core 上下文中都很重要,请尝试将程序集引用添加到这些文件,而不是使用 XML 配置。

标签: asp.net-core asp.net-core-mvc wif claims-based-identity


【解决方案1】:

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

从 cmets 看来,您正在解析 JWT,可能是使用 JWT 不记名令牌中间件。

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

【讨论】:

  • 那么等价的是什么?我有使用基于声明的身份验证方法的 web api。我还计划在核心项目上重用相同的方法,这样我就可以共享库并在两个项目上使用相同的密钥。 web api 项目已经在使用中。我应该完全放弃使用 asp.net 核心,如果还没有等价物,只使用 MVC 5 吗?
  • 你的意思是基于声明?您是指 WS-Fed 和 SAML,还是只是基于 ClaimsPrincipal 的某种身份。
  • 模板中有很多不同的项目可供选择,在选择什么和避免什么之间没有明确的路径。文档似乎不完整或过时
  • 如果你不能在这里解释你真正想要什么,那么我不能给你任何指导。从配置中看起来您想要联合,但是与 what 联合?以及正在使用哪些协议?
  • 通过将所有 web.config 部分放在 app.config 中解决了这个问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-10
  • 1970-01-01
  • 2017-11-08
  • 2020-04-15
相关资源
最近更新 更多