I am running multiple projects in my system, as shown below:
In this class, I cannot create a constructor. This is my class:
namespace Project.Common
{
public class Share
{
public const string SESSION_CURRENT_COMPANY = "Company";
public static int LoggedInMembersCompanyID
{
get
{
var companyIdSession = HttpContext.Session.GetInt32(Common.SESSION_CURRENT_COMPANY);
int _companyIdSessionID = 0;
if (companyIdSession != null)
{
int.TryParse(companyIdSession.ToString(), out _companyIdSessionID);
}
return _companyIdSessionID;
}
}
}
}
You have to add this in the startup.cs Configure Function just before app.UsesEndpoits
Common.Configure(app.ApplicationServices.GetRequiredService<IHttpContextAccessor>(), Configuration);
Go to the Common Project and Go to Common.cs add the following thing at the top:
private static IHttpContextAccessor _httpContextAccessor;
private static IConfiguration _configuration;
public static void Configure(IHttpContextAccessor httpContextAccessor,IConfiguration configuration)
{
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
public static int LoggedInMembersCompanyID
{
get
{
var companyIdSession = HttpContext.Current.Session[Share.SESSION_CURRENT_COMPANY];
int _companyIdSessionID = 0;
if (companyIdSession != null)
{
int.TryParse(companyIdSession.ToString(), out _companyIdSessionID);
}
return _companyIdSessionID;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.