I'm creating a web part on a non local server and I need to get the current user logged in to SharePoint. I'm using the following code to get the username.
string currentUser = SPContext.Current.Web.CurrentUser.LoginName;
However, it doesn't return the username of the person logged into SharePoint, instead it returns my username even if someone else is logged in. Does anyone know why this is happening?
I've also tried using the HttpContext and that doesn't work either.
Edit: The answer is kind of embarrassing. I had been storing all the users credentials in a static class, which is why it was always returning the wrong one- it was being set once and never changed. Thank you all for your help.