Click here to Skip to main content
15,890,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get UserName from SessionID variable
Posted
Comments
Pandya Anil 24-Nov-11 5:47am    
please elaborate... where is your userid, in sql or in asp.net session ?
Karthik Harve 24-Nov-11 5:50am    
if possible place some code
rajeevcapgeminiindia 24-Nov-11 6:19am    
While writing your question, try to give some suitable eaxmple so that it is easy to reply for the other members.
Mokshagna 15-Dec-11 0:35am    
I declared SessionID variable in my Global.asax page.
I'm using that SessionID in my aspx.cs page like "Session["UserID"].ToString"....
How can I get Session UserName from ID...Plz help on this...
RaviRanjanKr 15-Dec-11 16:13pm    
Always try to be more specific while asking question. :)

Try this
C#
if (HttpContext.Current.User != null)
               {
                   strName = HttpContext.Current.User.Identity.Name.ToString();
               }

Details refer
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx[^]
 
Share this answer
 
Comments
Mokshagna 15-Dec-11 0:29am    
I tried using the above code....

I got USERNAME which was in my login..it's like "PTC\210102" but how can I get name of that ID.please help on this...

Thank u!!!
RaviRanjanKr 15-Dec-11 16:11pm    
5+
 
Share this answer
 
Comments
RaviRanjanKr 15-Dec-11 16:11pm    
5+
Anuja Pawar Indore 16-Dec-11 0:48am    
Thanks Ravi :)
general:
from page1:
Session["em"] = TextBox1.Text.ToString();

textbox1 has the user name from page 1.

from page2:
string text2 = (String)Session["em"];
 
Share this answer
 
v2
Comments
RaviRanjanKr 15-Dec-11 16:12pm    
5+
To save the username in default.aspx use the following code
Session["name"] = txtname.text.ToString();


To retrieve the username from session in the page second.aspx use the following code


string fullname = (string)Session['name'];
 
Share this answer
 
v2
Comments
RaviRanjanKr 15-Dec-11 16:12pm    
5+

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