开发者

Force redirect to specific Action (ASP MVC)

开发者 https://www.devze.com 2022-12-10 20:51 出处:网络
In my ongoing web project i encountered a problem regarding redirection. The scenario is this: a) user logs on.

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 decorat开发者_如何转开发ing all the controllers with that particular class).

But how do i force the user to logout?

Thanks in advance


FormsAuthentication.SignOut removes the current forms authentication ticket from the browser. The user will then be required to authenticate themselves before accessing restricted resources.


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.


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....

0

精彩评论

暂无评论...
验证码 换一张
取 消