【发布时间】: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.html。
appsettings.json和project.json内容在 ASP .NET Core 上下文中都很重要,请尝试将程序集引用添加到这些文件,而不是使用 XML 配置。
标签: asp.net-core asp.net-core-mvc wif claims-based-identity