.net - 运行 "Identity and Access"向导后,带有 VS 2012 的 MVC4 应用程序中的 Principal 是 RolePrincipal 而不是 ClaimsPrincipal

标签 .net asp.net-mvc-4 visual-studio-2012 wif

由 Visual Studio 2012 中的默认(互联网)模板创建的 MVC 4 应用程序在运行“身份和访问...”向导后返回 RolePrincipal。

该向导创建与 STS(实际或“开发”时间 STS)的信任关系。

如果检查,用户对象的类型将是 角色校长 .这样做的结果是 User.IsInRole 针对本地角色数据库而不是声明集进行解析。

enter image description here

我期待一个 ClaimsPrincipal

最佳答案

这是因为新的 Oauth 支持。它使用了新的 simplemembership,它最终使用了所有的提供者。

删除 [InitializeSimpleMembership]帐户 Controller 上的属性是不够的,因为初始化发生在 WebMatrix.WebData 部件:

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

PreApplicationStartCode.Start 最终调用:
WebSecurity.PreAppStartInit();

如果检查,则表明:
     ...
SimpleRoleProvider simpleRoleProvider = WebSecurity.CreateDefaultSimpleRoleProvider("AspNetSqlRoleProvider", currentDefault2);
      Roles.Providers.Remove("AspNetSqlRoleProvider");
      Roles.Providers.Add((ProviderBase) simpleRoleProvider);
...

禁用所有这些“魔法”的方法是使用 web.config 中的此设置:
<add key="enableSimpleMembership" value="false"/>

关于.net - 运行 "Identity and Access"向导后,带有 VS 2012 的 MVC4 应用程序中的 Principal 是 RolePrincipal 而不是 ClaimsPrincipal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13463860/

相关文章:

c# - 是否可以在 visual studio 2013 update 2 中创建一个新的 windows phone 8 项目?

c# - Win Forms UserControl 未检测到按键

.net - DataContractSerializer:为什么不删除成员?

C# Linq To Excel 获取不在第一行开始的表数据

asp.net-mvc - MVC 4 Bundles Scripts.Render 每个文件的脚本标签

visual-studio - 如何使用 Visual Studio 2012 中的 MSBuild 文件?

sql-server - 安装 SQL Server 2012 SP1 后如何修复 VS 2012 中的 T-SQL 编辑器?

python - cx-freeze 与 .net 的 python 不兼容吗?

c# - .NET C# 在父接口(interface)中显式实现祖 parent 的接口(interface)方法

c# - 使用具有一对多关系的实体列表的属性更新数据库上的实体