I am trying to retrieve the username of the current user through ASP.NET
Currently I am retrieving it with
string user = Page.User.Identity.Name;
and I am trying to obtain the Student object that corresponds with the StudentNumber used to log into the Website.
above are the users and I am trying to only have the long/int before the @bit.com.
After this, I am trying to query it against the database like this:
IQueryable<Student> student = db.Students.Where(x => x.StudentNumber == user);
but currently I am unable to do so since my conversion of the username isn't working.
user = Utility.StringModifier.Modifier(GetType().Name, "@bit.com");
CodePudding user response:
string userName = Page.User.Identity.Name;
long studentNo = long.Parse(userName.Split('@')[0].Trim());
Then do your query:
IQueryable<Student> student = db.Students.Where(x => x.StudentNumber == studentNo );