Static field issue on asp.net website

I am currently working on an ASP.NET website. On one of my pages, I had a static field for the currently registered CompanyId user.

private static Guid _CompanyId = Company.Get().CompanyId;

The company .Get () returns information about the company of the current user, where the UserId is retrieved using:

System.Web.Security.Membership.GetUser();

But when you log in as another user, in antoher company, Company.Get (). CompanyId will return Guid from the first company.

Am I missing the point of using static fields, or does this have a different reason? I fixed this by replacing all references to _CompanyId in my code with Company.Get (). CompanyId for a quick fix, but this is not a good solution.

+3
source share
3

, , . . , , ..

+5

HttpContext.Current . -.

+3

Removing staticfrom your field definition should give you what you are looking for.

+1
source

Source: https://habr.com/ru/post/1716857/


All Articles