私はthis websiteを使用しています。角度2/4の.net core api認証を使用しています。.Net Core + Angular 2/4認証エラー
登録は機能しますが、認証(ログイン)時にトークンにエラーがあります。私は問題が何であるかを知らない
[AllowAnonymous]
[HttpPost]
public IActionResult Authenticate([FromBody]ApplicationUserDto applicationUserDto)
{
var appUser = _appUserService.Authenticate(applicationUserDto.Username, applicationUserDto.Password);
if (appUser == null)
return Unauthorized();
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, appUser.Id)
}),
Expires = DateTime.UtcNow.AddDays(7),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor); //Here returns the Error
var tokenString = tokenHandler.WriteToken(token);
// return basic user info (without password) and token to store client side
return Ok(new
{
Id = appUser.Id,
Username = appUser.Username,
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Token = tokenString
});
}
:HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
はここに私のコードです:サーバーは私に、このエラーが発生します。私は慎重にウェブサイトを使用してコード(コピー貼りではない)を書いた。エラーは何ですか?
ありがとうございました!