Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# ASP.NET核心Cookie身份验证_C#_Asp.net_Authentication_Cookies_Asp.net Web Api - Fatal编程技术网

C# ASP.NET核心Cookie身份验证

C# ASP.NET核心Cookie身份验证,c#,asp.net,authentication,cookies,asp.net-web-api,C#,Asp.net,Authentication,Cookies,Asp.net Web Api,我读了很多教程,我是如何做的应该是正确的,但我收到了意想不到的结果。 我正在创建我的ClaimsEntity/Principal,如下所示:(注意,在类库项目中,不是主WebApi项目。用户=来自数据库): 但是,当我调试控制器的User属性时,标识不包含任何声明、名称,并且isauthenticated设置为false。 但是,principal属性的isAuthenticated设置为true,因此SignIn方法本身存在问题? 所有后续请求也会将用户的身份显示为没有声明所有内容都为null

我读了很多教程,我是如何做的应该是正确的,但我收到了意想不到的结果。 我正在创建我的ClaimsEntity/Principal,如下所示:(注意,在类库项目中,不是主WebApi项目。用户=来自数据库):

但是,当我调试控制器的
User
属性时,标识不包含任何声明、名称,并且
isauthenticated
设置为false。
但是,
principal
属性的
isAuthenticated
设置为true,因此
SignIn
方法本身存在问题?
所有后续请求也会将
用户的身份显示为没有声明所有内容都为null或false

在我的StartUp.cs中,我有:

...
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "Custom.Identity",
    LoginPath = new PathString("/api/Account/Login"),
    AccessDeniedPath = new PathString("/api/Account/Denied"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});
app.UseMvc();
这是非常简单的代码,我做错了什么

await HttpContext.Authentication.SignInAsync("Custom.Identity", principal);
...
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "Custom.Identity",
    LoginPath = new PathString("/api/Account/Login"),
    AccessDeniedPath = new PathString("/api/Account/Denied"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});
app.UseMvc();