首先,我想为我真正糟糕的英语道歉,如果有些事情是不可理解的,那么请重新讨论。
当我在Swagger中使用/ api / account / regapi尝试POST时,如果密码太短,则会出现错误200,但是如果长度正确,则会给出错误500,而调试时会显示AuthDTO模型中的正确参数,但仍会显示错误500正确的数据。
false数据返回的响应头(密码长度不正确):
{
"$id": "1",
"succeeded": false,
"errors": [
{
"$id": "2",
"code": "PasswordTooShort",
"description": "Passwords must be at least 6 characters."
}
]
}
密码错误的响应标头
access-control-allow-origin: *
content-type: application/json; charset=utf-8
date: Sat, 26 May 2018 13:54:06 GMT
server: Kestrel
transfer-encoding: chunked
x-powered-by: ASP.NET
x-sourcefiles: =?UTF-8?B?RDpcS29vbGkgQXNqYWRcVlIyXFZSMlByb2pla3RTb2x1dGlvblxWUjJQcm9qZWt0XGFwaVxBY2NvdW50XFJlZ0FwaQ==?=
包含正确数据的响应标头:
content-type: text/html; charset=utf-8
date: Sat, 26 May 2018 14:03:59 GMT
server: Kestrel
transfer-encoding: chunked
x-powered-by: ASP.NET
x-sourcefiles: =?UTF-8?B?RDpcS29vbGkgQXNqYWRcVlIyXFZSMlByb2pla3RTb2x1dGlvblxWUjJQcm9qZWt0XGFwaVxBY2NvdW50XFJlZ0FwaQ==?=
在AccountController中注册
public async Task<IActionResult> RegApi(AuthDTO model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user, model.Password);
return Ok(result);
}
return BadRequest();
}
public class AuthDTO
{
public string Email { get; set; }
public string Password { get; set; }
}
我认为问题出现在_usermanager中,因为错误500开始显示在那里