Using HttpContext.Current in WebApi is dangerous because of async

前端 未结 3 485
感动是毒
感动是毒 2020-11-27 11:03

My question is a bit related to this: WebApi equivalent for HttpContext.Items with Dependency Injection.

We want to inject a class using HttpContext.Current in We

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 11:56

    I am using a web api, which is using async/await methodology.

    also using

    1) HttpContext.Current.Server.MapPath
    2) System.Web.HttpContext.Current.Request.ServerVariables
    

    This was working fine for a good amount of time which broke suddenly for no code change.

    Spending a lot of time by reverting back to previous old versions, found the missing key causes the issue.

    < httpRuntime targetFramework="4.5.2"  /> under system.web
    

    I am not an expert technically. But I suggest to add the key to your web config and give it a GO.

提交回复
热议问题