重定向后找不到会话值

Session values not found after redirect

在 Asp.net MVC 项目中,我在登录后将我的用户重定向到另一个页面。

在开发环境中我的所有会话变量return null.

然而,在生产环境中这工作正常并且会话变量被正确检索。

哪位能解释一下为什么在开发环境下所有的变量都是null

 [AllowAnonymous]
 [HttpPost]
 public ActionResult Login(LoginModel model, string returnUrl)
 {
    // Some validations 

     if (Url.IsLocalUrl(returnUrl))
          {
              var urlDeCoded = HttpUtility.UrlDecode(returnUrl);
              var htmlDecoded = HttpUtility.HtmlDecode(urlDeCoded);
              return Redirect(htmlDecoded);
          }
 }

/// Retreiveing session variables
 var vm = SessionData.GetCurrentObject<MembershipWizardViewModel>();

在 web.Config 中,我在两个环境中的 sessionState 具有相同的值,即 "InProc"

你松了你的会话吗? 我认为这可能是 cookie 的问题:会话 ID 可以保存在 cookie 中,如果您重定向到位于不同服务器上的 Url,cookie 是不同的,因此它会为您创建一个新会话...带有空变量。 一个常见的错误是从 "localhost" 重定向到“127.0.0.1”,即使在技术上相同,也会造成很多麻烦。