Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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# 在Web Api 2中获取HttpContext.Current.User.Identity.Name null通过Web Api 4登录 bool iss=HttpContext.Current.User.Identity.IsAuthenticated; 国际空间站{ UserManager.FindByName(HttpContext.Current.User.Identity.Name); 字符串名称=HttpContext.Current.User.Identity.name } 我得到的名称为空,并通过身份验证是真实登录 带有angular 2的asp.net web api 上面给出了Web配置,我也尝试mode=“Windows”_C#_Angular_Asp.net Web Api_Asp.net Identity - Fatal编程技术网

C# 在Web Api 2中获取HttpContext.Current.User.Identity.Name null通过Web Api 4登录 bool iss=HttpContext.Current.User.Identity.IsAuthenticated; 国际空间站{ UserManager.FindByName(HttpContext.Current.User.Identity.Name); 字符串名称=HttpContext.Current.User.Identity.name } 我得到的名称为空,并通过身份验证是真实登录 带有angular 2的asp.net web api 上面给出了Web配置,我也尝试mode=“Windows”

C# 在Web Api 2中获取HttpContext.Current.User.Identity.Name null通过Web Api 4登录 bool iss=HttpContext.Current.User.Identity.IsAuthenticated; 国际空间站{ UserManager.FindByName(HttpContext.Current.User.Identity.Name); 字符串名称=HttpContext.Current.User.Identity.name } 我得到的名称为空,并通过身份验证是真实登录 带有angular 2的asp.net web api 上面给出了Web配置,我也尝试mode=“Windows”,c#,angular,asp.net-web-api,asp.net-identity,C#,Angular,Asp.net Web Api,Asp.net Identity,我解决了我的问题,我使用了GenerateUserIdentityAsync()方法而不是此方法 bool iss = HttpContext.Current.User.Identity.IsAuthenticated; if(iss) { UserManager.FindByName(HttpContext.Current.User.Identity.Name); string name = HttpContext.Current.User.Iden

我解决了我的问题,我使用了
GenerateUserIdentityAsync()
方法而不是此方法

 bool iss = HttpContext.Current.User.Identity.IsAuthenticated;
 if(iss) {
          UserManager.FindByName(HttpContext.Current.User.Identity.Name);
          string name = HttpContext.Current.User.Identity.Name
}


<authentication mode="None" />
    <remove name="FormsAuthentication" />
我的代码现在运行良好

var identity = new ClaimsIdentity(context.Options.AuthenticationType);
public override异步任务GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext)
{
var userStore=new CustomUserStore(new ApplicationDbContext());
var-manager=新的UserManager(userStore);
var user=wait manager.FindAsync(context.UserName,context.Password);
如果(用户!=null)
{
//var identity=newclaimsidentity(context.Options.AuthenticationType);
ClaimsIdentity identity=wait user.GenerateUserIdentityAsync(manager);
AddClaim(新声明(“UserId”,user.Id.ToString());
identity.AddClaim(新声明(“Username”,user.Username.ToString());
identity.AddClaim(新声明(“电子邮件”,user.Email));
AddClaim(新声明(“UserRole”,新RoleManagerBusinessLogic().GetRoleNameByRoleId(user.Roles.FirstOrDefault().RoleId));
AddClaim(新声明(“LoggedOn”,DateTime.UtcNow.ToString());
上下文验证(身份);
}
其他的
返回;
}

我解决了我的问题,我使用了
GenerateUserIdentityAsync()
方法而不是此方法

 bool iss = HttpContext.Current.User.Identity.IsAuthenticated;
 if(iss) {
          UserManager.FindByName(HttpContext.Current.User.Identity.Name);
          string name = HttpContext.Current.User.Identity.Name
}


<authentication mode="None" />
    <remove name="FormsAuthentication" />
我的代码现在运行良好

var identity = new ClaimsIdentity(context.Options.AuthenticationType);
public override异步任务GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext)
{
var userStore=new CustomUserStore(new ApplicationDbContext());
var-manager=新的UserManager(userStore);
var user=wait manager.FindAsync(context.UserName,context.Password);
如果(用户!=null)
{
//var identity=newclaimsidentity(context.Options.AuthenticationType);
ClaimsIdentity identity=wait user.GenerateUserIdentityAsync(manager);
AddClaim(新声明(“UserId”,user.Id.ToString());
identity.AddClaim(新声明(“Username”,user.Username.ToString());
identity.AddClaim(新声明(“电子邮件”,user.Email));
AddClaim(新声明(“UserRole”,新RoleManagerBusinessLogic().GetRoleNameByRoleId(user.Roles.FirstOrDefault().RoleId));
AddClaim(新声明(“LoggedOn”,DateTime.UtcNow.ToString());
上下文验证(身份);
}
其他的
返回;
}