title: httpcontextaccessor null reference on app service but not debug
body: <p>I have a weird issue I can't explain.</p>
  <p>I have a helper class in my Blazor Server Side app that does arb functions for my app.  I added  <code>services.AddHttpContextAccessor();</code> in startup,</p>
  <p>declared it in my helper class</p>
  <pre><code>public GlobalHelper(IHttpContextAccessor accessor, 
              IOptions&lt;AzureADB2COptions&gt; azureAdB2COptions,
              IConfiguration configuration
              
             )
          {
              _accessor = accessor;
              AzureAdB2COptions = azureAdB2COptions.Value;
              Configuration = configuration;
              
          }
  </code></pre>
  <p>and then have a function to return the userid:</p>
  <pre><code> public string GetUserID()
      {
          var context = _accessor.HttpContext;
  
  
          return context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
  </code></pre>
  <p>and then in my page, I just want to display it first on a button click event:</p>
  <pre><code> @inject Classes.GlobalHelper _helper
  
  &lt;h1&gt;Counter&lt;/h1&gt;
  
  &lt;p&gt;Current count: @currentCount&lt;/p&gt;
  
  &lt;button class=&quot;btn btn-primary&quot; @onclick=&quot;IncrementCount&quot;&gt;Click me&lt;/button&gt;
  
  
  @code {
  
      string currentCount = &quot;test&quot;;
  
      void IncrementCount()
      {
          var test4 = httpContextAccessor.HttpContext;
  
          var authState = AuthenticationStateProvider.GetAuthenticationStateAsync();
          var user = authState.Result.User;
          if (user.Identity.IsAuthenticated)
          {
  
              try
              {
              
  
                  currentCount = _helper.GetUserID().Result;
                  
              }
              catch (Exception ex)
              {
  
                  currentCount = ex.ToString();
              }
  
  
          }
          else
          {
              Console.WriteLine(&quot;The user is NOT authenticated.&quot;);
          }
  
  
      }
  }
  </code></pre>
  <p>If I just debug locally, this works fine.  As soon as I publish this to an app service in Azure... I get a <code>nullreferenceexception</code> on accessing the <code>httpcontextaccessor</code> in the globalhelper class. This line:</p>
  <pre><code>return context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
  </code></pre>
  <p>What could I be doing wrong so that the httpcontext is null in the app service and not in debug on my local machine?</p>