savvas sopiadis
savvas sopiadis

Reputation: 1704

Force redirect to specific Action (ASP MVC)

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

Answers (3)

Sailing Judo
Sailing Judo

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

pmarflee
pmarflee

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

Langdon
Langdon

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

Related Questions