user20358
user20358

Reputation: 14736

system.identityModel not detected in web.config

I have an ASP.NET Core 1.0 project running. When I add the ClaimsPrinciplePermission attribute to my action methods I get the following error when navigating to any action method having that attribute.

An exception of type 'System.InvalidOperationException' occurred in System.IdentityModel.Services.dll but was not handled in user code

Additional information: ID7024: Use of ClaimsPrincipalPermission attribute has been attempted and possibly there is no configuration section defined, see inner exception for details. Also make sure a ClaimsAuthorizationManager element is defined under the section.

This is the inner exception

ID7027: Could not load the identity configuration because no configuration section was found.

This is my 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>

As you can see, I have added all the required sections. The same code and configuration works well in my MVC 5 projects and also my Web Api project. Is there something different to be done in Asp.Net Core projects?

I have also added the required DLL references in the Core 1.0 MVC project as well duplicated the same configuration sections in the App.config file under the core 1.0 MVC project. Still getting the same error.

What am I missing?

Upvotes: 4

Views: 6510

Answers (1)

blowdart
blowdart

Reputation: 56500

ClaimsPrincipalPermission, and WIF/System.IdentityModel is not part of .NET Core at all. I'm surprised that even compiles.

From the comments it appears you're parsing a JWT, presumably with the JWT bearer token middleware.

So, all identities in ASP.NET Core are ClaimsIdentities. You can go for Simple claims based checks, or, more fully to code expressed policies which give a lot more flexibility.

Upvotes: 2

Related Questions