FormsAuthentication.SignOut 未按预期工作

发布于 2024-11-05 11:05:59 字数 561 浏览 0 评论 0原文

我在我的 ASP.NET Web 应用程序中使用表单身份验证。当用户单击“退出”按钮时,我执行以下代码:

  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();

它有效。问题是,在注销之前,如果我复制当前所在的受限页面的 URL,然后注销,我可以将该 URL 粘贴回浏览器并返回受限页面,绕过登录页面。

我的网络配置如下所示:

<authentication mode="Forms">
    <forms name="NoiseAdvisor" loginUrl="~/Login.aspx" timeout="20" slidingExpiration="true" cookieless="AutoDetect" protection="All" requireSSL="false" defaultUrl="~/Restricted/Home.aspx"/>
</authentication>

我缺少什么吗?

I'm using Forms authentication in my asp.net web app. When the user clicks the 'sign out' button, I execute the following code:

  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();

which works. The problem is, before signing out, if I copy the url of the restricted page that I'm currently on, then sign out, I can paste the URL back into the browser and return to the restricted page, bypassing the login page.

My web config looks like this:

<authentication mode="Forms">
    <forms name="NoiseAdvisor" loginUrl="~/Login.aspx" timeout="20" slidingExpiration="true" cookieless="AutoDetect" protection="All" requireSSL="false" defaultUrl="~/Restricted/Home.aspx"/>
</authentication>

Is there something I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁与争疯 2024-11-12 11:05:59

您能否确认该页面没有被您的浏览器缓存并且您实际上看到的是缓存版本?按 Shift-F5 并查看页面是否刷新或者是否重定向到登录页面。如果是这种情况,您可以使用缓存设置来确保用户无法返回该页面。

Can you confirm that the page is not cached by your browser and you are actually seeing a cached version? Press Shift-F5 and see if the page refreshes or if you are redirected to the login page instead. If that is the case, you can play with the cache settings to make sure users cannot go back to the page.

舂唻埖巳落 2024-11-12 11:05:59

当您将 URL“粘贴”到浏览器中时,它将为您提供该页面的缓存版本(与您上次访问的视图相同),除非您明确禁用该页面的客户端缓存。正如 cdonner 提到的,按 Shift+F5,我猜它会将您踢到登录页面。

When you "paste" a URL into your browser, it is going to give you a cached version of the page (same view as your last visit) unless you've explicitly disabled client caching for the page. As cdonner mentioned, press Shift+F5 and I'm guessing it will kick you to the login page.

做个少女永远怀春 2024-11-12 11:05:59

您是否检查过以确保正确限制页面?

如:

  <location path="RestrictedPage.aspx">
    <system.web>
      <authorization>
        <deny users="?" />
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

或者,您可以在受限页面上物理查看:

if (!(HttpContext.Current.User == null))
    if (HttpContext.Current.User.Identity.IsAuthenticated)
          // show restricted content

Have you checked to make sure you're restricting the page correctly?

Such as:

  <location path="RestrictedPage.aspx">
    <system.web>
      <authorization>
        <deny users="?" />
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

Or, you can physically check on the restricted page:

if (!(HttpContext.Current.User == null))
    if (HttpContext.Current.User.Identity.IsAuthenticated)
          // show restricted content
筱武穆 2024-11-12 11:05:59

这对我有用

public virtual ActionResult LogOff()
    {
        FormsAuthentication.SignOut();
        foreach (var cookie in Request.Cookies.AllKeys)
        {
            Request.Cookies.Remove(cookie);
        }
        foreach (var cookie in Response.Cookies.AllKeys)
        {
            Response.Cookies.Remove(cookie);
        }
        return RedirectToAction(MVC.Home.Index());
    }

This works for me

public virtual ActionResult LogOff()
    {
        FormsAuthentication.SignOut();
        foreach (var cookie in Request.Cookies.AllKeys)
        {
            Request.Cookies.Remove(cookie);
        }
        foreach (var cookie in Response.Cookies.AllKeys)
        {
            Response.Cookies.Remove(cookie);
        }
        return RedirectToAction(MVC.Home.Index());
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文