[SOLVED] Triming the email portion of a username ASP.NET

Issue

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.

[email protected] |
[email protected]

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");

Solution

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 );

Answered By – Rahatur

Answer Checked By – Clifford M. (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *