我收到以下错误:
{“类型声明'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'或'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/提供的ClaimsIdentity上没有identityprovider' . 要使用基于声明的身份验证启用防伪令牌支持,请验证配置的声明提供程序是否在它生成的ClaimsIdentity实例上提供这两个声明 . 如果配置的声明提供程序使用将不同的声明类型作为唯一标识符,可以通过设置静态属性AntiForgeryConfig.UniqueClaimTypeIdentifier来配置它 . “}
我试过Anti-forgery token issue (MVC 5)没有成功 .
发生错误
@Html.AntiForgeryToken()
Generic Startup.cs
public class Startup
{
public void Configuration(IAppBuilder app)
{
AuthConfig.ConfigureAuth(app);
}
}
Admin Controller Login Method
[HttpPost]
public ActionResult Login(Models.AdminUserLogin LoginModel)
{
if (ModelState.IsValid)
{
if (isUserValid(LoginModel.EmailAddr, LoginModel.Password))
{
List<Claim> claims = new List<Claim>
{
new Claim(ClaimTypes.Email, LoginModel.EmailAddr),
//some other claims
};
ClaimsIdentity identity = new ClaimsIdentity(claims, AuthConfig.DefaultAuthType);
IAuthenticationManager authManager = Request.GetOwinContext().Authentication;
authManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, identity);
return RedirectToAction("Manage");
}
else
{
ModelState.AddModelError("", "Username and/or password incorrect");
}
}
return View(LoginModel);
}
任何想法都将非常感激 .
1 回答
在你的
ClaimsIdentity
中,你需要这两个声明来防止伪造令牌: