I have a ControllerBase
class in an ASP.NET MVC Application. The other controllers inherit from ControllerBase
.
I want to access HttpContext.User.Identity.Name
, but HttpContext
is null
. What's the matter?
public ControllerBase()
{
var dataManager=new DataManager();
if (HttpContext.User.Identity.IsAuthenticated) // throws error
{
ViewData["assets"] = ud.BalanceFreeze + ud.Balance + ud.BalanceRealty;
ViewData["onaccount"] = ud.Balance;
ViewData["pending"] = ud.BalanceFreeze;
ViewData["inrealty"] = ud.BalanceRealty;
}