Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to use session variables in login form and redirect to another page after successful login.
Posted

 
Share this answer
 
Comments
VJ Reddy 24-Apr-12 8:03am    
5!
Sandeep Mewara 24-Apr-12 8:37am    
:)
when the user is authenticate successfully then get the data from the table from which you authenticate the user and store that data into session like this



C# syntax
C#
session["Userid"] = dt.rows[0]["UserName"];



in vb


VB
Session("UserId") = dt.rows(0)("UserName")


here user name is the column of the database table in which you store the user data.
 
Share this answer
 
v2
Comments
Karthik Harve 24-Apr-12 1:57am    
[Edit] pre tags added
Yeah as Shabbir suggested-

C# syntax
session["Userid"] = dt.rows[0]["UserName"];
Response.Redirect("AnotherPage.aspx");  



--AnotherPage.aspx

On this page's Page load Function check whether the sessions exists or not by using "If" statement,If User Session Doesnot exists then redirect to Login Page as

if(session["Userid"]==null)
{
Response.Redirect("login.aspx");  
}
 
Share this answer
 
v2
Hi,
For this,

first, You can to assign the value of session varable on click event of login button (after Authentication and just before the Redirect to Another page). To assign the value, Use the following code in VB:

VB
Session("VariableName")="SomeValue"



and the load event of every page that comes after login (i.e. All the secured pages that you want user cant see wihout login), just check whether Session("VariableName") is null or not, if it is null, then redirect it to Login Page. Here is the code for the same:

VB
If session("VariableName") Is Nothing Then
    Response.Redirect("login.aspx")
End If
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900