I have the following inheritance hierarchy in my ASP.net MVC 3 app:
public class HomeController : AuthenticatedBaseController
{
public ActionResult Index()
{
return View();
}
}
public class AuthenticatedBaseController : BaseController
{
public AuthenticatedBaseController()
{
if (!this.UserToken.IsAuthenticated)
{
RedirectToAction("Login", "Login");
}
}
}
public class BaseController : Controller
{
private Token _token;
public Token UserToken
{
get
{
_token = (Token)(Session["token"]);
if (_token == null)
{
SetToken();
}
return _token;
}
}
public void SetToken()
{
_token = new Token(Session.SessionID, Request.Url.Host, Request.Url.ToString());
Session["token"] = _token;
}
}
I am finding that the constructor of the AuthenticatedBaseController is firing twice when I make a GET request to /Home. Can someone help tell me what I am doing wrong?
Authorizeauthorization filters.