C# 会话丢失它';ASP.NET MVC 5中的间歇

C# 会话丢失它';ASP.NET MVC 5中的间歇,c#,asp.net-mvc-5,C#,Asp.net Mvc 5,您看到会话间歇性丢失其值的原因了吗 public ActionResult Index(string app) // this view hits the Create Controller on a form post event { Session["appType"] = app; return View(); } [HttpPost] public ActionResult Create(string

您看到会话间歇性丢失其值的原因了吗

    public ActionResult Index(string app) // this view hits the Create Controller on a form post event
    {
       Session["appType"] = app;         
       return View();
    }
    [HttpPost]
    public ActionResult Create(string userName, string password)
    {
        string a = Session["appType"].ToString(); // throws object reference error.
    }
  • 检查web.config中的sessionState元素。在非活动超时(分钟)后,您将丢失会话
  • 您将看到如下代码:

    <sessionState mode="SQLServer"
        cookieless="true "
        regenerateExpiredSessionId="true "
        timeout="30"
        sqlConnectionString="Data Source=MySqlServer;Integrated Security=SSPI;"
        stateNetworkTimeout="30"/>
    
    
    
  • 您是否可以在负载平衡器后面运行此应用程序?如果是这样,则在会话期间可能不会将用户路由到同一台计算机

  • 附加信息-“a”是未使用的变量。不确定这是否是原因。嗨,谢谢你的信息。我还没有把它说清楚。所以我想它会采用默认设置。