c# - 切换到身份时的 Azure ClaimsIdentity

标签 c# asp.net azure

我最近将我的 ASP.NET 应用程序从 Azure 的 Active Directory 配置切换到 ASP.NET Identity。我在本地测试时没有遇到任何问题,但当我发布到 Azure 时,出现以下错误:

A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.

就配置而言,我应该在 Azure 端更改一些内容吗?或者我的代码中还需要其他东西吗?

最佳答案

如果您没有使用 ACS 作为 STS,那么上述错误几乎告诉您需要采取什么措施来解决该问题。

您需要告诉 MVC 您要使用哪个声明来唯一标识用户。您可以通过设置 AntiForgeryConfig.UniqueClaimTypeIdentifier 属性(通常在 global.asax 的 App_Start 中)来执行此操作。例如(假设您想使用 nameidentifier 作为唯一声明):

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);

    AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
}

关于c# - 切换到身份时的 Azure ClaimsIdentity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32449401/

相关文章:

c# - VSTO 自定义 Outlook 文件夹上下文菜单

c# - 滚动时 Gridview 卡住/固定标题丢失背景颜色

c# - 如何使用 C# asp.net 在静态方法中查找 Div id

javascript - 将值作为数组从 html 传递到 javascript

architecture - Azure 上的高流量、每天超过 5 亿次点击(类似分析)的应用程序架构

azure - 如何在 Cosmos DB 中对两个容器进行内连接

c# - 加速 File.Exists 用于不存在的网络共享

c# - BotFramework 和 LUIS 的 JSON 序列化器错误

c# - 在 C# 中将 char 转换为 int

c# - 异步调用方法和/或在其自己的线程上调用方法以提高性能