title: Why does System.Web.HttpContext.Current.User.Identity.Name return an empty string?
body: <p>I have the following code to verify if the user has access to the application or not. Problem is <code>System.Web.HttpContext.Current.User.Identity.Name</code> returns empty. I checked. What could be the problem? My other application uses the same code snippet and it works there. Why is this happening?</p>
  
  <pre><code>string username = System.Web.HttpContext.Current.User.Identity.Name;
  string str = "SELECT LASTNAME +', '+ FIRSTNAME AS NAME, USER_NAME, DEPARTMENT FROM DBNAME.DBO.TABLENAME WHERE USER_NAME = '" + username + "' ";
  SqlCommand cmd = new SqlCommand(str, conn);
  SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  if (rdr.HasRows == false)
  {
  
          Server.Transfer("unauthorized.htm");
  }
  else
  {
      while (rdr.Read())
      {
          name = rdr["NAME"].ToString();
          username = rdr["USER_NAME"].ToString();
          dept = rdr["DEPARTMENT"].ToString();
      }
  }
  </code></pre>