title: Exception Details: System.Security.SecurityException: A specified logon session does not exist. It may already have been terminated
body: <p>I deployed a test web app to virtual Windows server 2008 std. IIS does not have certificates features assigned to this app nor to any apps deployed on this server so none of the solutions I've found relate to my issue.  All other apps  on same server work fine which leads me to conclusion the problem must be with the code I am using to authenticate in the global.asax file.    </p>
  
  <p>I've checked gpedit.msc and <em>Network access: Do not allow storage of credent</em>ials is already disabled.  <a href="https://stackoverflow.com/questions/23111915/cannot-get-a-user-via-windows-authentication-a-specified-logon-session-does-no">This posting</a> is closest to my issue that I've been able to find but no solution was accepted. I've checked MMC but there is nothing in it but an empty Console Root node so there is nothing to delete and reinstall as some have suggested <a href="http://bartwullems.blogspot.in/2012/08/iis-manager-error-specified-logon.html" rel="nofollow noreferrer">here</a> and <a href="https://stackoverflow.com/questions/14953132/iis-7-error-a-specified-logon-session-does-not-exist-it-may-already-have-been/25854919#25854919">here</a>. I cannot access blog sites from work-there were some that sounded promising but I can't read them. I added Full Trust to web.config it made no difference and noted that .NET Trust Levels in IIS  were set at Full (internal) already.</p>
  
  <p>The complete error message is:  </p>
  
  <pre><code>System.Security.SecurityException: A specified logon session does not exist. It may already have been terminated.
  
     at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
     at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
     at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
     at EPRSystem.Global.IsInADGroup(String user, String group)
     at EPRSystem.Global.Application_AuthenticateRequest(Object sender, EventArgs e)
  The Zone of the assembly that failed was:
  MyComputer
  </code></pre>
  
  <p>Any ideas for me?</p>
  
  <p>Here's my global code:</p>
  
  <pre><code>    public Boolean IsAdmin;
      public Boolean IsManager;
      public Boolean IsDeveloper;
  
      string UserName;
  
     public String GetUserName()
     {
          WindowsIdentity wiCurrentUser;
          wiCurrentUser = WindowsIdentity.GetCurrent();
  
          String strUserName = wiCurrentUser.Name;
  
          String[] strParts = strUserName.Split('\\');
          strUserName = strParts[1];  
  
          return strUserName; 
     }
  
     public Boolean IsInADGroup(string user, string group)
     {
         using (var identity = new WindowsIdentity(user))
         {
             var principal = new WindowsPrincipal(identity);
  
             return principal.IsInRole(group);
         }
     }   
  
  
      protected void Session_Start(object sender, EventArgs e)
      {
          //Write method: Get current user's username
  
          UserName = HttpContext.Current.User.Identity.Name; //get AD name of user
  
          HttpContext.Current.Session["UserName"] = GetUserName();
  
          HttpContext.Current.Session["IsAdmin"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group1");
  
          HttpContext.Current.Session["IsManager"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group2");
  
          HttpContext.Current.Session["IsDeveloper"] = IsInADGroup(HttpContext.Current.Session["UserName"].ToString(), "group3");  
      }
  
  
      protected void Application_AuthenticateRequest(object sender, EventArgs e)
      {
          //Write method: Identity/Authenticate current user
  
          DAL.ErrorLog oErrorLog = new DAL.ErrorLog();
          try
          {
              String strUser = GetUserName();
  
              IsAdmin = IsInADGroup(strUser, "group1");
  
              IsManager = IsInADGroup(strUser, "group2");
  
              IsDeveloper = IsInADGroup(strUser, "group3");
          }
          catch (System.Security.SecurityException ex)
          {
              oErrorLog.WriteErrorLog(ex.ToString());
          }
  
      }  
  </code></pre>