简体   繁体   English

ASP.NET AJAX 登录验证...取消页面加载?

[英]ASP.NET AJAX login validation… cancel page load?

I have the following issue:我有以下问题:

In my web.config I have the following authorization setup:在我的 web.config 我有以下授权设置:

<authentication mode="Forms">
    <forms loginUrl="~/LogIn" timeout="2880" name=".ASPXFORMSAUTH" defaultUrl="~/Dashboard/Dashboard.aspx"/>
</authentication>

The code I inherited from previous development stores a user object into Session after logging in. I am planning on continuing to use this logic for now.我从以前的开发中继承的代码在登录后将用户 object 存储到 Session 中。我现在计划继续使用这个逻辑。

Now, a user navigates to the page.现在,用户导航到该页面。 Cookie is created as they log in, and user info stored into Session. Cookie 在他们登录时创建,用户信息存储在 Session 中。 The user now closes the page's tab, but keeps the browser open.用户现在关闭页面的选项卡,但保持浏览器打开。 The user waits x amount of time causing Session to expire, but not the cookie.用户等待 x 时间导致 Session 过期,但不是 cookie。 The user now attemps to navigate directly to the page they were at previous.用户现在尝试直接导航到他们之前所在的页面。 Forms authentication thinks they are logged in, but they are not. Forms 认证认为自己登录了,其实没有。 As such, my logged in user is null.因此,我的登录用户是 null。

I am attempting to do this:我正在尝试这样做:

protected void Page_Init(object sender, EventArgs e)
{
    if (object.Equals(DashboardSessionRepository.Instance.LoggedInUser, null))
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
    else
    {
        //Continue with page init
    }
}

Unfortunately, this does not cause the current page to cancel its lifecycle.不幸的是,这不会导致当前页面取消其生命周期。

I am wondering a few things:我想知道几件事:

  • How is this scenario properly handled in the field?如何在现场正确处理这种情况?
  • Is this an acceptable solution if not the correct solution?如果不是正确的解决方案,这是一个可接受的解决方案吗?
  • Is there a way to prevent myself from having to check if LoggedInUser is null during the rest of my page lifecycle events (page load, pageloadcomplete)?在我的页面生命周期事件(页面加载,页面加载完成)的 rest 期间,有没有办法防止自己检查 LoggedInUser 是否为 null? I assume I could set AutoWireEvents to false, but wiring up my own lifecycle seems more wrong.我假设我可以将 AutoWireEvents 设置为 false,但连接我自己的生命周期似乎更错误。

Thanks谢谢

Unfortunately, this does not cause the current page to cancel its lifecycle.不幸的是,这不会导致当前页面取消其生命周期。

If you wish to stop the life cycle just place the End that after the RedirectToLoginPage... as如果您希望停止生命周期,只需将 End 放在 RedirectToLoginPage... 之后

if (object.Equals(DashboardSessionRepository.Instance.LoggedInUser, null))
{
    FormsAuthentication.SignOut();
    FormsAuthentication.RedirectToLoginPage();
    Response.End();
    return;
}
else

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM