[英]OWIN Authentication:async method lacks 'await' operators
I have implemented OWIN authentication in my project.But when I try to build the project, it is showing some errors.我已经在我的项目中实现了 OWIN 身份验证。但是当我尝试构建项目时,它显示了一些错误。
The methods which are showing errors :显示错误的方法:
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//code
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//code
}
The showing error is显示错误是
This async method lacks 'await' operators and will run synchronously.
此异步方法缺少“等待”运算符,并且将同步运行。 Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
考虑使用 'await' 运算符来等待非阻塞 API 调用,或使用 'await Task.Run(...)' 在后台线程上执行 CPU 密集型工作。
How can I fix this issue?我该如何解决这个问题?
If you are not using an await
operator in the implementation of the function then you can remove the async
modifier.如果您没有在函数的实现中使用
await
运算符,那么您可以删除async
修饰符。
However, once you remove it, the compiler will expect you to provide a return value for Task
.但是,一旦您删除它,编译器将期望您为
Task
提供返回值。 You can obviously create a Task
however you choose, but in this instance you might want to just return the following (which is discussed here ):您显然可以根据自己的选择创建一个
Task
,但在这种情况下,您可能只想返回以下内容( 此处讨论):
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
return Task.FromResult<object>(null);
}
async
is not part of the signature. async
不是签名的一部分。 Just because you're overriding an async
method doesn't mean that you have to mark your override as async
.仅仅因为您覆盖
async
方法并不意味着您必须将覆盖标记为async
。
So, if you don't have any await
s in your code, just remove the async
mark.因此,如果您的代码中没有任何
await
,只需删除async
标记。
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
//code
}
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.