I'm trying to design a homepage for an MVC site that has two different views, based on if the user is logged in or not.
So image the default (not logged in) view is showing general, nonspecific info. If i'm logged in, the view is showing mostly personal stuff instead.
What's the best practice to handling this? Don't forget, we also need to unit test this.
Thanks heaps!
This should be a simple case of returning the appropriate view from your controller.
public ActionResult Index()
If (User.IsLoggedOn)
{
// Do user-specific controller stuff here...
return View("LoggedOnIndex");
}
else
{
// Do anon controller stuff here...
return View("AnonymousIndex");
}
I'm not sure if you could do
User.IsloggedOn
in the past, but now I have to say
User.Identity.IsAuthenticated
if you are using the Built In Web Forms Authentication.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With