Reputation: 9084
I'm currently working on an ASP.NET web-site. In one of my pages, I had a static field for the current logged in user's CompanyId.
private static Guid _CompanyId = Company.Get().CompanyId;
Company.Get() returns the information about the company of the currently logged in user, where the UserId is retrieved using:
System.Web.Security.Membership.GetUser();
But when logging in as another user, in antoher company, Company.Get().CompanyId would return the Guid from the first company.
Have I missed the point of using static fields, or does this have another cause? I fixed it, by replacing all the references to _CompanyId in my code-behind with the Company.Get().CompanyId for a quick fix, but this is not really a good solution.
Upvotes: 5
Views: 2936
Reputation: 52241
static variable value persist at the application level and hence across user wise. you should use session to store your information. static variable value is not change until you reassign the value, application restart, etc..
Upvotes: 8
Reputation: 31761
Removing static
from your field definition should give you what you're looking for.
Upvotes: 1
Reputation: 878
You should use HttpContext.Current to store session level variables. static variables are visible to all sessions in your web application.
Upvotes: 3