我已经在我的项目中实现了OWIN身份验证。但是当我尝试构建项目时,它显示了一些错误。
显示错误的方法:
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//code
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//code
}
显示错误是
此异步方法缺少'await'运算符并将同步运行。考虑使用'await'运算符等待非阻塞API调用,或'await Task.Run(...)'在后台线程上执行CPU绑定工作。
如何解决此问题? 提前感谢您的答案!
答案 0 :(得分:1)
async
不是签名的一部分。仅仅因为您覆盖了async
方法并不意味着您必须将覆盖标记为async
。
因此,如果您的代码中没有await
,请删除async
标记。
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//code
}
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//code
}
答案 1 :(得分:1)
如果您在执行该功能时未使用await
运算符,则可以删除async
修饰符。
但是,一旦删除它,编译器就会期望您为Task
提供返回值。显然,您可以选择创建Task
,但在这种情况下,您可能只想返回以下内容(discussed here):
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
return Task.FromResult<object>(null);
}