Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 标识的方案名称是什么?_C#_Asp.net Core_Asp.net Identity_Asp.net Core Identity_.net Core Authorization - Fatal编程技术网

C# 标识的方案名称是什么?

C# 标识的方案名称是什么?,c#,asp.net-core,asp.net-identity,asp.net-core-identity,.net-core-authorization,C#,Asp.net Core,Asp.net Identity,Asp.net Core Identity,.net Core Authorization,假设我使用以下方法: services.AddIdentity<User, UserRole>() .AddEntityFrameworkStores<AppDbContext>(); services.AddIdentity() .AddEntityFrameworkStores(); 正在设置的身份验证方案名称是什么?我在任何文档中都没有找到这个。我试图寻找一个名为IdentityAuthenticationDefaults和IdentityDef

假设我使用以下方法:

services.AddIdentity<User, UserRole>()
        .AddEntityFrameworkStores<AppDbContext>();
services.AddIdentity()
.AddEntityFrameworkStores();
正在设置的身份验证方案名称是什么?我在任何文档中都没有找到这个。我试图寻找一个名为
IdentityAuthenticationDefaults
IdentityDefaults
的类,但什么也找不到。我尝试过“饼干”,但它没有设置为这个。应用程序运行良好,因此肯定有一些方案名称集

是您在这里寻找的课程。以下是您具体问题的相关部分(已删除xmldocs):

IdentityConstants.ApplicationScheme
用作
DefaultAuthenticateScheme
-值本身最终为
Identity.Application

这些计划已设立:

以下是API参考文档的链接:


请注意,IdentityConstants下有静态字符串引用,但AuthorizationAttribute类或方法属性无法使用这些引用来设置AuthenticationSchemes属性,因为它必须是常量。我创建了一个简单的shared constants类,该类包含解决此问题的必要步骤,但希望MS提供一些OOTB

public class SharedConstants
{
    public const string IdentityApplicationScheme = "Identity.Application";
}
然后你可以像这样使用它

[Authorize(AuthenticationSchemes = SharedConstants.IdentityApplicationScheme)]

谢谢,它解决了这个问题。然而,由于这不是一个常数,有没有关于如何在没有硬编码身份的情况下使用它的想法?我想创建一个自定义身份验证方案需要很长的路要走。一个自定义策略应该适合这一点-请参阅以了解其工作原理。
public class SharedConstants
{
    public const string IdentityApplicationScheme = "Identity.Application";
}
[Authorize(AuthenticationSchemes = SharedConstants.IdentityApplicationScheme)]