如何使用async / await执行此操作,以便同时评估这两个条件? 这是我目前正在处理的代码。我尝试使用带有条件的Result并收到死锁。
else if (!string.IsNullOrEmpty(customer))
{
var resp = await _securityService.GetCustomerShiptoAuthorizationAsync(User.Identity.Name, customer, ship);
response = Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Username, Password, Customer or Ship.");
}
这是以前的非异步/等待代码,并且一起评估条件。
else if (!string.IsNullOrEmpty(customer) && !_securityService.GetCustomerShiptoAuthorization(
User.Identity.Name,
customer,
ship).IsAuthorized)
{
response = Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Username, Password, Customer or Ship.");
}
答案 0 :(得分:1)
将括号括在await
来电。
else if (!string.IsNullOrEmpty(customer) && !(await _securityService.GetCustomerShiptoAuthorizationAsync(User.Identity.Name, customer, ship).IsAuthorized))
{
response = Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid Username, Password, Customer or Ship.");
}