我正在尝试使用微服务实现 Asp.net 核心身份。我为身份创建了一个微服务。迁移身份并创建表。我创建了另一个项目来显示来自微服务的值。我成功地使用微服务获取和发布值。但是在将值发布到身份微服务时,错误显示 StatusCode 404 Not found。
下面是Identity微服务中通过调用identity来消费Web API的代码
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(User user)
{
HttpClient client = api.Initial();
var postTask = client.PostAsJsonAsync<User>("identity", user);
postTask.Wait();
var result = postTask.Result;
if (result.IsSuccessStatusCode)
{
return RedirectToAction("Index");
}
return View(user);
}
下面是身份 API 控制器的 Post 方法
[HttpPost]
public async Task<IActionResult> Post([FromBody] UserViewModel user)
{
var idenUser = new MembershipUser();
idenUser.Email = user.Email;
idenUser.ChurchId = user.ChurchId;
idenUser.IsDeleted = false;
idenUser.PhoneNumber = user.MobileNo;
idenUser.UserName = user.LoginName;
var resultCreate = await userManager.CreateAsync(idenUser,
user.Password);
if (resultCreate.Succeeded)
{
return StatusCode(StatusCodes.Status201Created, user);
}
else
{
return StatusCode(StatusCodes.Status404NotFound, user);
}
}
下面是身份 API 的 ocelot.json API geteway 代码
{
"DownstreamPathTemplate": "/api/IdentityAPI",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "57608"
}
],
"UpstreamPathTemplate": "/identity",
"UpstreamHttpMethod": [ "GET", "POST" ]
},
{
"DownstreamPathTemplate": "/api/IdentityAPI/{id}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "57608"
}
],
"UpstreamPathTemplate": "/identity/{id}",
"UpstreamHttpMethod": [ "GET", "PUT", "DELETE" ]
}