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.
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..
You should use HttpContext.Current to store session level variables. static variables are visible to all sessions in your web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With