prevent页面生命周期? [英] Prevent page life cycle?

查看:240
本文介绍了prevent页面生命周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有上有一个注销链接母版页。当用户点击该链接我叫下面的方法:

I have a master page with a logout link on it. When the user clicks the link I call the following method:

    private void Logout()
    {
        SessionBll.DeleteSessionEntry(this.sessionId);
        FormsAuthentication.SignOut();
        Roles.DeleteCookie();
        LogHelper.Location = string.Empty;

        LogHelper.Info(logger, HttpContext.Current.User.Identity.Name, 
           MethodBase.GetCurrentMethod().Name, "User has been logged out from 
                Administrator.Master", LogMessage.LoggedOut);
        FormsAuthentication.RedirectToLoginPage();
    }

现在,当用户在页面上,他们点击链接,正常的页面周期发生,这种方法被调用。

Now, when a user is on a page and they click the link, the normal page cycle happens and this method is called.

问题这个是用户不应该等待页面周期,应尽可能快地采取注销页面(只要它需要运行在服务器上注销方法)。

The problem with this is that the user shouldn't have to wait for the page cycle, they should be taken to the logout page as fast as possible (as long as it takes to run the logout method on the server).

我如何跳过页面生命周期,但仍然调用此方法?

How do I skip the page life cycle, yet still call this method?

感谢。

推荐答案

您不能跳过页面生命周期;你可以做什么,而不是是这样的:

You can't skip the page life cycle; what you can do instead is this:

更改了注销链接到一个正常的链接(< A HREF =...> )和的Page_Load 登录页面,执行该code你张贴,但只有如果(!的IsPostBack)

Change that logout link to a normal link (<a href="...">) and on Page_Load of the Login page, execute that code you posted but only if(!IsPostBack)

修改

如果您的登录页面需要知道(因为你把它)时,执行你的清理code;你可以通过注销链路上的参数,像这样:

If your Login page needs to know (as you put it) when to execute your cleanup code; you can pass a parameter on the logout link as so:

<a href="Login.aspx?Logout=y" > Logout </a>

然后检查的Page_Load:

And then check on Page_Load:

if (!IsPostBack &&  Request.QueryString["Logout"]=="Y" )
{
   //Your code here
}

这是超级快。

这篇关于prevent页面生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆