The principal in an MVC4 application with VS 2012 is RolePrincipal instead of ClaimsPrincipal after running the Identity and Access wizard

The MVC 4 application created by default template (Internet) in Visual Studio 2012 returns RolePrincipal after running the "identity and access ..." wizard.

The wizard builds trust with STS (either STA or development time).

When validating, the user object will be of type RolePrincipal . The consequence of this is that User.IsInRole removes the database of local roles, and not a set of requirements.

enter image description here

I was expecting ClaimsPrincipal

+4
source share
1 answer

This is due to the new Oauth support. It uses the new simplemembership, which is located below, using all providers.

Removing the [InitializeSimpleMembership] attribute in the account controller is not enough, because initialization occurs in the WebMatrix.WebData strong> assembly :

 [assembly: PreApplicationStartMethod(typeof (PreApplicationStartCode), "Start")] 

PreApplicationStartCode.Start terminates the call:

 WebSecurity.PreAppStartInit(); 

This, if checked, shows:

  ... SimpleRoleProvider simpleRoleProvider = WebSecurity.CreateDefaultSimpleRoleProvider("AspNetSqlRoleProvider", currentDefault2); Roles.Providers.Remove("AspNetSqlRoleProvider"); Roles.Providers.Add((ProviderBase) simpleRoleProvider); ... 

How to disable all this β€œmagic” using this parameter in the web.config file:

 <add key="enableSimpleMembership" value="false"/> 
+5
source

Source: https://habr.com/ru/post/1447089/


All Articles