WebJul 13, 2012 · In addition to the other answers here, while Controller.Session is not populated in the constructor, you can still access the session through: System.Web.HttpContext.Current.Session with the standard caveat that this potentially reduces your controller's testability. Share Improve this answer Follow edited Jan 14, … WebDec 31, 2014 · You can pass the context around by using constructor injection. Inject the owincontext into your logic layer as constructor parameter. I think the problem is that HttpContext does not exist at the time Startup is called, so what you probably need, is to have a Func instead, like this: public class PacientasEntityRepo:IEntityRepo
Get an existing session in my BaseController constructor
WebAug 31, 2024 · Might be useful. I needed the action in the constructor of the controller, and it appears at this point of the MVC lifecycle, this hasn't initialized, and ControllerContext = null.Instead of delving into the MVC … WebJun 16, 2024 · In the new MVC Core it seems the standard way to get the context to the controller is by doing this. public class BaseController : Controller { public readonly ReportDBContext _db; public BaseController (ReportDBContext db) { _db = db; } } I can then use. public class HomeController : BaseController { public HomeController … palace disco
How to access the Session in ASP.NET Core via static variable?
WebOct 5, 2024 · Before was easier to access the httpContext outside the controller but in .Net Core, I see the need to use injection. I have read a lot of articles and the process is to: ... Call the class from the Controller's constructor; See details here at Microsoft: https: ... WebOct 2, 2009 · Try initializing stuff in the ApplicationController's Initialize method, HttpContext isn't avaliable in the constructor. Make sure to call base.Initialize () or you can get some interesting results. Share Follow answered Oct 1, 2009 at 20:33 Wyatt Barnett 15.6k 3 32 52 1 where do I call this base.Initialze ()? I am not sure where to stick it WebMar 19, 2024 · It’s only necessary to add this dependency if we want to access HttpContext in service. To use HttpContext in service we need to do following two … palace edition cars