Reputation: 823
I'm trying to sign out a user when a session object don't exist with following code in my View:
FormsAuthentication.SignOut();
But this doesn't work - the user is already authenticated.
I've seen that the default LogOff Controller
Action use this code to signout a user:
AuthenticationManager.SignOut();
But I can't use this code in my view.
So how can I logout a user in my View? Or when it's not possible how can I do this in a Controller?
Thanks for help :)
Upvotes: 4
Views: 7350
Reputation: 5479
You would be doing this in a controller, for instance in a separate action like LogOut()
. After you've done your logout, redirect the user to the front page (for instance).
Then you simply make a link to that action.
The view is not a place to contain anything but purely simple presentational logic, like if
statements or for
loops. Controllers should take care of application behaviour like logging out.
Upvotes: 3