本文介绍了Httpcontext在await函数中变为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是使用异步等待的示例。
当我们执行任何代码时,等待httpcontext变为空
我尝试过:
Below is the sample of using async await.
when ever we execute any code inside await httpcontext is getting null
What I have tried:
//Here is the sample of Async Function in which i cant get Httpcontext
public async Task<string> Get(int id)
{
var x = HttpContext.Current;
if (x == null)
{
// not thrown
throw new ArgumentException("HttpContext.Current is null");
}
await Task.Run(() => { GetRealId(); });
return "value";
}
//HttpContext Getting null here..
public void GetRealId()
{
var r = HttpContext.Current;
}
推荐答案
这篇关于Httpcontext在await函数中变为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!