title: HttpContext.Current is Nothing (same as null in C#) in asmx web service
body: <pre><code>Imports System.Web.Services
  Imports System.Web.Services.Protocols
  Imports System.ComponentModel
  
  &lt;System.Web.Services.WebService(Namespace:="http://tempuri.org/")&gt; _
  &lt;System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _
  &lt;ToolboxItem(False)&gt; _
  
  Public Class Starter
      Inherits System.Web.Services.WebService
  
      &lt;WebMethod()&gt;
      Public Shared Sub Invoke()
          Dim webForm = New WebForm1()
          ScriptManager.RegisterStartupScript(webForm, GetType(Page), "Execute", "document.getElementById('confirm').click;", True)
          HttpContext.Current.Response.Redirect("Dashboard.aspx") 'System.NullReferenceException
  
          MsgBox(HttpContext.Current IsNot Nothing) 'False
      End Sub
  
  End Class
  </code></pre>
  
  <p>I have already googled for other questions (here or in other websites). Many have mentioned about <code>EnableSession = True</code>. I have tried it in my code but an error message was shown after that:</p>
  
  <blockquote>
    <p>'EnableSession' is not declared. It may be inaccessible due to its protection level.</p>
  </blockquote>
  
  <p>How can I fix the <code>HttpContext.Current</code>? Do I need to add any configuration settings to web.config for asmx web service? Thanks</p>