HttpContext.Current Is Null

As I integrating the Auth0 ASP.Net (System.Web) into our applicaion I got the error on line 61 of the LoginCallback.ashx. The Error: ID1061: HttpContext.Current is null. Checking in our Auth0 Log, we have successfully logged in and Auth0 has all the information from our login through two different social sign ins. So from something within the retrieval of the information is in conflict. No where else in the project are we using HttpContext so it is not deleted through any means.

.Net framework #4.6.1 and using C#6

To Go from start to finish as I have it set up as: Login Page->Redirected to Auth0 Login Page->LoginCallback(Where the error occurs)

I had tried both Lock page imbedded in the project and external login page to see if it was either or that was the issue and is an error on both.

Unmodified the entire page here it is:

public override async Task ProcessRequestAsync(HttpContext context)
        {
            AuthenticationApiClient client = new AuthenticationApiClient(
                new Uri(string.Format("https://{0}", ConfigurationManager.AppSettings"auth0:Domain"])));

            var token = await client.GetTokenAsync(new AuthorizationCodeTokenRequest
            {
                ClientId = ConfigurationManager.AppSettings"auth0:ClientId"],
                ClientSecret = ConfigurationManager.AppSettings"auth0:ClientSecret"],
                Code = context.Request.QueryString"code"],
                RedirectUri = context.Request.Url.ToString()
            });

            var profile = await client.GetUserInfoAsync(token.AccessToken);

            var user = new List<KeyValuePair<string, object>>
            {
                new KeyValuePair<string, object>("name", profile.FullName ?? profile.PreferredUsername ?? profile.Email),
                new KeyValuePair<string, object>("email", profile.Email),
                new KeyValuePair<string, object>("family_name", profile.LastName),
                new KeyValuePair<string, object>("given_name", profile.FirstName),
                new KeyValuePair<string, object>("nickname", profile.NickName),
                new KeyValuePair<string, object>("picture", profile.Picture),
                new KeyValuePair<string, object>("user_id", profile.UserId),
                new KeyValuePair<string, object>("id_token", token.IdToken),
                new KeyValuePair<string, object>("access_token", token.AccessToken),
                new KeyValuePair<string, object>("refresh_token", token.RefreshToken)
            };
FederatedAuthentication.SessionAuthenticationModule.CreateSessionCookie(user);
            if (context.Request.QueryString"state"] != null && context.Request.QueryString"state"].StartsWith("ru="))
            {
                var state = HttpUtility.ParseQueryString(context.Request.QueryString"state"]);
                context.Response.Redirect(state"ru"], true);
            }
            context.Response.Redirect("/");
        }
       public bool IsReusable{
            get { return false; }
        }

The error in question is associated with .NET so it has little to do with the Auth0 integration; the only reason you get it there is because like you said, you’re not using HttpContext.Current anywhere else. In addition, a quick search for the error ID1061: HttpContext.Current is null. suggests that one possible explanation is trying to access this within an ASP .NET Core application which won’t have that available.

The .NET and ASP.NET terms serve as an umbrella for quite a few variants of the technology stack and target platforms so you need to adjust accordingly. In particular, if you’re targeting ASP .NET Core then for a web application you should be following the ASP.NET Core Introduction quickstart and not the System.Web one.