首页 > 解决方案 > 写入 Session 会中断 ASP.NET MVC OpenId 登录

问题描述

试图理解为什么在使用带有 OpenID Connect 的 ASP.NET Web 应用程序时写入 Session 会中断登录过程。

让我们考虑一个微软设计的例子https://github.com/AzureADQuickStarts/AppModelv2-WebApp-OpenIDConnect-DotNet

        public ActionResult Index()
        {
            return View();
        }


        /// Send an OpenID Connect sign-in request.
        public void SignIn()
        {
            if (!Request.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties { RedirectUri = "/" },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        }

        /// Send an OpenID Connect sign-out request.
        public void SignOut()
        {
            HttpContext.GetOwinContext().Authentication.SignOut(
                    OpenIdConnectAuthenticationDefaults.AuthenticationType,
                    CookieAuthenticationDefaults.AuthenticationType);
        }

它工作正常,直到我在 Session 中写了一些东西:

        public ActionResult Index()
        {
            Session["TEST"] = "TEST"; // Let's make a SignIn disruption
            return View();
        }

一旦我这样做,登录就会停止工作;它会将您重定向到 Microsoft AD,后者将返回未经身份验证的索引。此外,在重新启动应用程序之前,在调试期间删除此代码将不起作用。有时它允许您进行一轮 SingIn/SingOut,但所有连续的 SignIn 都失败。

任何人都知道为什么会发生这种情况以及从哪里开始寻找解决方案?

标签: asp.net-mvcsessionsession-cookiesopenid

解决方案


推荐阅读