I have an MVC application what restricts the user from accessing controller actions based on a value stored in the session.
I have implemented as follows:
public partial class MyBookingController : CruisesDesktopControllerBase
{
private bool CheckLoggedIn()
{
return MyBookingSessionInfo.OzBookingId > 0;
}
public virtual ActionResult Summary()
{
//Ensure user is logged in
if (!CheckLoggedIn())
return RedirectToAction(MVC.MyBooking.Login());
//Prepare the view model
SummaryViewModel summaryViewModel = new SummaryViewModel
{
OzBookingId = MyBookingSessionInfo.OzBookingId
};
return View(summaryViewModel);
}
}
So instead of doing the if test at the top of controller actions I want to protect, is there a way to do this where the controller action could be annotated in some way to enforce the "logged in restriction" and hence removing the if test block?