Reputation: 1704
In my ongoing web project i encountered a problem regarding redirection. The scenario is this:
a) user logs on.
b) the count of records in a specific table determines if the user will be redirected to a specific controller/action
c) user arrives in that particular controller/action and does something here
d) (after having done what must be done) the user must be forced to log out (can this be done somehow automatically?)
I think i already implemented this scenario until c) using ActionFilterAttribute (by decorating all the controllers with that particular class).
But how do i force the user to logout?
Thanks in advance
Upvotes: 0
Views: 574
Reputation: 11243
Assuming you are using FormsAuthentication, I have a Logout method looking something like this:
public static string Logout(HttpContext context, string defUrl)
{
FormsAuthentication.SignOut();
var vir = context.Request.ApplicationPath;
return String.IsNullOrEmpty(vir)
? defUrl
: VirtualPathUtility.Combine(vir, defUrl);
}
The FormsAuthentication.SignOut() is the key part....
Upvotes: 0
Reputation: 3428
FormsAuthentication.SignOut removes the current forms authentication ticket from the browser. The user will then be required to authenticate themselves before accessing restricted resources.
Upvotes: 1
Reputation: 20073
It really depends on what "logging" out means in your application. It could be as simple as Session.Abandon in your action before you redirect anywhere.
Upvotes: 0