Subscribe to Subscribers

Forums » .NET » ASP.NET »

How to assign values to session state and access those value to a particular user in asp.n


Posted Date: 11 Jul 2012      Posted By:: Anu George     Member Level: Silver    Member Rank: 1128     Points: 1   Responses: 4



how to assign values to session state and access those value to a particular user in asp.net after login



Responses

#679853    Author: Usha Vasanth      Member Level: Bronze      Member Rank: 4322     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Assign session as below:

Session["UserId"] = LoginId;

Access session to a user as below:

string UserNew = Convert.ToString(Session["UserId"]);


 
#679854    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi Anu,


Session is state management technique which is used to maintain the user data in the server.

Refer the below Ex:


In LoginPage.aspx's Login button storing Session["username"].

protected void btnLogin_Click(object sender, EventArgs e)
{
if (CheckUserCredentials(txtUserName.Text.ToString().Trim(), Encrypt(txtPassword.Text.ToString().Trim(), true)))
{

if (dtLoginuserDetails.Rows.Count > 0)
{
Session["username"] = txtUsername.text;
}
}

Sample.aspx

Using Session["username"] in sample.aspx, if it is k then it will open sample.aspx

protected void Page_Load(object sender, EventArgs e)
{
if ((Session["username"] == null) || (Session["username"] == "") || (Session["username"] == string.Empty))
{
Server.Transfer("sample.aspx");
return;
}
In Logout.aspx use the below..
Session.Abandon();
will close the session




Hope this will give you some Idea

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too


 
#679886    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

Session is used to keep values across pages in the same website. Refer below code sample to understand that concept


//Initialize - During login in inside of login button click event
session["loginuser"] = "name of the user";

//Calling like this
Label1.Text = Session["loginuser"].ToString();

//Remove like this
Session.Remove("loginuser");

//Remove all session values
Session.RemoveAll();


Regards
N.Ravindran
Your Hard work never fails





 
#679926    Author: suresh Babu M      Member Level: Silver      Member Rank: 701     Date: 11/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

you can store the values in session by assign the values to session.

you can retrieve the value from session and you can show that session value to particular user by calling session value.

Regards


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : How to show data in two columns and two rows in listview
Previous : Reading OLE Object from SQL Anywhere
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.