title: Using session for user authentication in asp.net c#
body: <p>I am using session to authenticate a user. I have 2 web pages in my project. One is webform and other one is <code>EntryForm.aspx</code> and other one is <code>log.aspx</code></p>
  <p>In log.aspx i have done</p>
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
          user_login loginu = new user_login();
          String uid_db = loginu.login(this.DropDownList1, this.TextBox1, this.TextBox2, this.Label5);
          if (uid_db == &quot;invalid&quot;)
          {
              Label5.Visible = true;
              Label5.Text = &quot;Invalid Login&quot;;
          }
          else
          {
  
              string uname = uid_db.Substring(0, uid_db.IndexOf(&quot;,&quot;)).Trim();
              string[] tokens = uid_db.Split(',');
              string dbname = tokens[tokens.Length - 1];
  
              Session[&quot;login&quot;] = uname;
              Session[&quot;db&quot;] = dbname;
              Response.Redirect(&quot;EntryForm.aspx&quot;);
         }
  }
  </code></pre>
  <p>In class <code>user_login</code> I am taking the password stored in the database and matching it with the value entered by user. if it finds a value i redirect it to EntryForm.aspx. In which i check for session variable as follows</p>
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {// CHEK SESSION VARIABLE AND LOAD dropdownlist1 WITH VALUES
          if (!IsPostBack)
          {
              String DB = &quot;&quot;;
              String AccountID = &quot;&quot;;
              if (Session[&quot;login&quot;] != null &amp;&amp; Session[&quot;db&quot;] != null)
              {
                  AccountID = Session[&quot;login&quot;].ToString();
                  DB = Session[&quot;db&quot;].ToString();
  
                  Label9.Text = AccountID;
              }
              else
              {
                  Response.Redirect(&quot;log.aspx&quot;);
              }
              HiddenField1.Value = DB.ToString();
              DropDown a = new DropDown();
              a.filldropdown1(this.DropDownList1, DB);
          }
      }
  </code></pre>
  <p>This is what i have done do authenticate a user. On server i have done the following configuration:</p>
  <p><img src="https://i.stack.imgur.com/gSSG2.jpg" alt="enter image description here" /></p>
  <p>I have done no settings in <code>Global.asax</code> nor anything is <code>web.config</code> . I have seen many forum wherein <code>Global.asax</code> and <code>web.config</code> is configured.</p>
  <p>I want to know what do i need to do in my project in order to be very efficient to work. I am facing problem with session timeout. I have set it to 20 mins on my server but sometimes suddenly i get logged out.</p>
  <p>Please help me to understand using session for authentication.</p>