Skip to main content

how to maintain session in asp 3.5 with c#

There are different ways. You can use form authentication , it's a way to do that.

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="30"
           name=".ASPXAUTH" 
           path="/"
           requireSSL="false"
           slidingExpiration="true"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>

<authorization>  
    <allow users="admin" />
    <deny users="*" />
</authorization>
</system.web>
private void btnLogin_Click(object sender, System.EventArgs e)
{
 if (Validate(txtUsername.Text, txtPassword.Text))
 {
  FormsAuthentication.Initialize();
  String strRole = txtUsername.Text;  
  FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, 
   txtUsername.Text, DateTime.Now, 
   DateTime.Now.AddMinutes(30), false, strRole, 
   FormsAuthentication.FormsCookiePath);
  Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, 
   FormsAuthentication.Encrypt(fat)));
  Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false));
 }
 else
  lblError.Visible = true;
}

private Boolean Validate(String strUsername, String strPassword)
{
    return ((strUsername == "admin") && (strPassword == "password"));
}
 


In logout page you can use the following code

private void Page_Load(object sender, System.EventArgs e)
{
 Session.Abandon();
 FormsAuthentication.SignOut();
}


remeber this kind of authentication works only user enables cookies

Comments

Popular posts from this blog

CIVIL SERVICES' (I.A.S.) EXAMINATION

The Union Public Service Commission (U.P.S.C.)  conducts Civil Services' Examination once a year in two stages. The Preliminary Examination (Objective Type) for selection of candidates for the Main Examination is held in the month of May. The Civil Services Main Examination  is held in the months of October/November. Blank application forms and other particulars are published in the Employment News, generally in the month of December. The last date for the submission of applications to the Secretary, Union Public Service Commission, Dholpur House, Shahjahan Road, NewDelhi-11001 1 is usually the last week of January of the year of examination. The Combined Civil Services Examination is conducted for Recruitment to the following Services/Posts: 1. Indian Administrative Service. 2. Indian Foreign Service. 3. Indian Police Service. 4. Indian P & T Accounts & Finance Service, Group 'A'. 5. Indian Audit and Accounts Service, Group 'A'. 6. Indian Customs and Centr...

(B) Basic Question in .net(dotNet) What is a IL?

(B)What is a IL? Twist :- What is MSIL or CIL , What is JIT? (IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In- Time (JIT) compiler.

Placement Guide

Placement Guide Posts are Under Following Topics If You Have Any Questions : Contact us 1. Recruitment Patterns Of Various Companies Recruitment Patters 2. Interview Questions :- On various topics : C C++ Java Advanced Java DBMS Data Structure Operating System Web Technologies 3. Aptitude Tests (Practice Test Papers on various Topics) : Quantitative Aptitude 4. Placement Papers : (Previous Years Aptitude Papers) - of various Companies : Accenture Amdocs Capgemini Cognizant Deloitte Government Job HCL IBM infosys microsoft Oracle Persistent TCS Tech Mahindra     Learn Languages Here : Important Programming Languages  If You Have Any Questions : Contact us