ASP.NET HttpContext is null in 4.6.1 sample project

自古美人都是妖i 提交于 2019-12-12 09:57:07

问题


1) Create new MVC app targeting 4.6.1 (not core, using MSVS 2015 Update 3)

2) In the generated class ApplicationUser.cs add an assertion:

public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
     HttpContext httpContext = HttpContext.Current;
     Debug.Assert(httpContext != null);  // assertion fails
     // ...
}

3) Run program in the debugger, login, the assertion fires.

This workaround fixes the problem however I was told that HttpContext should be available across async/await as of .NET 4.5. Should I need the workaround?

Web.Config:

 <httpRuntime targetFramework="4.6.1" />

来源:https://stackoverflow.com/questions/38340880/asp-net-httpcontext-is-null-in-4-6-1-sample-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!