Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 05, 2012 12:15 AM by EnenDaveyBoy
Dec 03, 2012 08:37 PM|LINK
Is there a best way to determine if the user is logged in, within the view? I can determine it in the controller and then send a viewbag to the view to check, but thought there might be a better way.
I was thinking of setting up a baseviewmodel to send but at present I don't need view models so I think it would be overkill.
Dec 04, 2012 12:42 AM|LINK
You can use - User.Identity.IsAuthenticated within the view, its available as part of view.
Dec 04, 2012 12:43 AM|LINK
Yes, you can use either one of these:
Those properties are set after the user is authenticated.
Dec 04, 2012 08:40 AM|LINK
is it good practise or is it better to do it in the controller?
Dec 04, 2012 10:23 AM|LINK
You can do it in the View if you use it just to decide what to show in the view, that is, wich parts of the Voew to show to the logged user. If you need it tom do compex data retrieval tasks...then it is better to move it in the controller.
Dec 04, 2012 04:27 PM|LINK
Those proprties are available to the view to allow us to enable a logout button and other UI elements that depend on the user's login status. This is a common practice.
Dec 05, 2012 12:15 AM|LINK
many thanks all