Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow ,I have a scenario whereby each logged in student Has a StudentId,i have to get the studentId so as i can use it to add a new record,The issue is i can use the code below which returns to me the name of the user currently logged.I dont know how to get the studentId of that logged in user.This is how i am trying to do but am stuck,Can someone guide me as each user has a UserId,So i have to pass the userId to get the studentId


C#
MembershipUser user = Membership.GetUser(Page.User.Identity.Name);

If i pass it this format it adds a record but i dont want to do it this way,just how i can get it from the logged in user
C#
int studentId=21;
Posted
Updated 19-Dec-13 22:22pm
v3
Comments
Gaurav Makwana 20-Dec-13 6:41am    
if you make webapplication then you need to take login id as session or if you make windows application then define one string variable globally and at the time of student login just pass login id value to this globally variable then you can use it everwhere in you application!
Member 10398773 20-Dec-13 7:07am    
The session Id is the StudentId but everytime its giving me null results
Gaurav Makwana 20-Dec-13 7:22am    
how? if user loged in then how it shows null

ok just write down your code in try catch and check why id doest take any value ?
its easy just try! if you getting then again prob just let me know

1 solution

This solved It

MembershipUser user = Membership.GetUser(Page.User.Identity.Name);
Guid id = new Guid(user.ProviderUserKey.ToString());

int studentId =Students.GetstudentId(id);
 
Share this answer
 

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