0

로그인 컨트롤러에 이와 같은 코드가 있습니다. 나는 사용자가 올바른 사용자 이름과 암호로 로그인 할 때 쿠키와 세션을 만듭니다.몇 분이 지나면 쿠키가 만료됩니까? 시간 초과가 제대로 작동하지 않습니다.

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; 

는 그리고 난 다음의 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 분 만료 시간 제한을 설정합니다. 모든 것이 옳은 것처럼 보입니다. 그리고 로컬 서버에는 문제가 없습니다. 그러나이 프로젝트를 서버에 게시 할 때 시스템이 5 분 동안 사용하지 않으면 홈/색인 (로그인 페이지)으로 사용자를 리디렉션합니다.

이유를 알 수 없습니다. 제가 누락 된 것이 있습니까?

컴퓨터 키와 관련된 문제 일 수 있습니까? 이 문제를 어떻게 해결할 수 있습니까?

답변

0

기계 키를 사용하여 문제가 해결되었습니다.

컴퓨터 키를 생성하고 web.config에 추가했습니다. 내 웹 설정 파일의

for generate machine key

최종 버전

<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> 
관련 문제