I’m trying to figure out which part of my program is causing this error.
I have multiple pages that all inherit from PageBase. They get their user profile from PageBase. This is the function that gets their user name from PageBase:
uiProfile = ProfileManager.FindProfilesByUserName(CompanyHttpApplication.Current.Profile.UserName)
In the CompanyHttpApplication I have
public static CompanyHttpApplication Current
{
get { return (CompanyHttpApplication)HttpContext.Current.ApplicationInstance; }
}
and
public CompanyProfileInfo Profile
{
get
{
return profile ??
(profile =
ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.Authenticated,
User.Identity.Name).Cast
<CompanyProfileInfo>().ToList().First());
}
private set { profile = value; }
}
Unfortunately I did not write this section of the code and the programmer who did it is no longer on the project. Is there any one that can explain to me why, when another user logs in (while I am using the application), I become that user?
The Application instance is shared across every request — the application level.
You want the Session level — each user gets their own instance.
Use
HttpContext.Current.Sessioninstead of ApplicationInstance.(Code below renames original, and adds a property, to be more clear. Feel free to adjust as necessary.)