Asp.net mvc 饼干几分钟后过期?超时不能正常工作

Asp.net mvc 饼干几分钟后过期?超时不能正常工作,asp.net-mvc,session,forms-authentication,session-cookies,session-timeout,Asp.net Mvc,Session,Forms Authentication,Session Cookies,Session Timeout,我在登录控制器中有这样的代码。当用户使用正确的用户名和密码登录时,我会创建cookie和会话 Models.DTO.Security.CustomPrincipalSerializeModel serializeModel = new Models.DTO.Security.CustomPrincipalSerializeModel(); serializeModel.Id = member.Id; serializeModel.UserName = member.UserName; seria

我在登录控制器中有这样的代码。当用户使用正确的用户名和密码登录时,我会创建cookie和会话

Models.DTO.Security.CustomPrincipalSerializeModel serializeModel = new Models.DTO.Security.CustomPrincipalSerializeModel();
serializeModel.Id = member.Id;
serializeModel.UserName = member.UserName;
serializeModel.RoleId = member.RoleId;
serializeModel.IsAdmin = member.IsAdmin;

JavaScriptSerializer serializer = new JavaScriptSerializer();
string userData = serializer.Serialize(serializeModel);
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
    1,
    model.UserName,
    DateTime.Now,
    DateTime.Now.AddMinutes(60),
    false,
    userData
    );
string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
{
    HttpOnly = true

};
Response.Cookies.Add(faCookie);


Session["CartItemsCount"] = 0;

Session["CartItems"] = new List<Models.DTO.CartDTO.CartVM>();

Session["DiscountPercentage"] = member.DiscountPercentage;

Session["CreditLimit"] = member.CreditLimit;
Models.DTO.Security.CustomPrincipalSerializeModel serializeModel=new Models.DTO.Security.CustomPrincipalSerializeModel();
serializeModel.Id=member.Id;
serializeModel.UserName=member.UserName;
serializeModel.RoleId=member.RoleId;
serializeModel.IsAdmin=member.IsAdmin;
JavaScriptSerializer serializer=新的JavaScriptSerializer();
string userData=serializer.Serialize(serializeModel);
FormsAuthenticationTicket authTicket=新的FormsAuthenticationTicket(
1.
model.UserName,
日期时间,现在,
DateTime.Now.AddMinutes(60),
假,,
用户数据
);
字符串encTicket=FormsAuthentication.Encrypt(authTicket);
HttpCookie faCookie=新的HttpCookie(FormsAuthentication.formscookeName,encTicket)
{
HttpOnly=true
};
响应.Cookies.添加(faCookie);
会话[“CartItemsCount”]=0;
会话[“CartItems”]=新列表();
会话[“折扣百分比”]=成员折扣百分比;
会话[“CreditLimit”]=member.CreditLimit;
我有以下Web.config文件:

<system.web>
    <sessionState timeout="60"/>
    <authentication mode="Forms">
      <forms loginUrl="~/Home/Index" timeout="60" name=".ASPXAUTH" />
    </authentication>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>

我将超时时间设置为60分钟后在everywhere中过期。一切似乎都很好。本地服务器也没有问题。 但当我在服务器上发布这个项目时,系统会在5分钟不活动后将用户重定向到主页/索引(登录页面)

我不明白为什么。我有什么遗漏吗


问题是否与机器钥匙有关?如何解决这个问题?

我用机器钥匙解决了这个问题

我生成了一个机器密钥并将其添加到web.config

我的web配置文件的最终版本

 <system.web>
        <machineKey 
validationKey="5DEBFB5B7BA6F3E1DB190A2BF28F08AEB8964618C2895BD931A735143D1A9C61DA59443F8B407F125447A663452F76AB82F18E4191911E3D563700CD4CA27138"
decryptionKey="A0048282BE5B72D6028F46820C87A360906430E9E3D8EDE09BAB79E95AF4B9A2"
validation="SHA1" decryption="AES"
/>
        <sessionState timeout="60"/>
        <authentication mode="Forms">
          <forms loginUrl="~/Home/Index" timeout="60" name=".ASPXAUTH" />
        </authentication>
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
        <httpModules>
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
        </httpModules>
      </system.web>