반응형
양식 인증 시간 초과 대 세션 시간 초과
나의 asp.net 웹사이트에서 나는 다음 구성을 가진 asp.net 양식 인증을 사용하고 있습니다.
<authentication mode="Forms">
<forms loginUrl="~/Pages/Common/Login.aspx"
defaultUrl="~/Pages/index.aspx"
protection="All"
timeout="30"
name="MyAuthCookie"
path="/"
requireSSL="false"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" >
</forms>
</authentication>
다음과 같은 질문이 있습니다.
양식 인증 전에 만료될 세션으로 인해 양식 인증 내부에서 슬라이딩 만료를 사용하고 있으므로 세션의 시간 초과 값이 무엇이어야 합니다.어떻게 보호할 수 있을까요?
인증 로그아웃 후 logout.aspx에서 페이지를 리디렉션하고 싶지만 loginpage.aspx에서 자동으로 리디렉션됩니다.그게 어떻게 가능해?
- 안전한 쪽으로 가기 위해:시간 초과(세션) <= 시간 초과(양식 인증) * 2
- 인증 시간 초과 후 loginUrl 특성에 지정되지 않은 페이지를 표시하려면 ASP.NET이 이를 수행하는 방법을 제공하지 않으므로 이를 수동으로 처리해야 합니다.
#2를 달성하기 위해 쿠키와 쿠키의 인증을 수동으로 확인할 수 있습니다.만료 티켓을 발급하고 만료된 경우 사용자 지정 페이지로 리디렉션합니다.
다음 이벤트 중 하나에서 수행할 수 있습니다.요청 상태 획득, 요청 인증.
이벤트의 샘플 코드는 다음과 같습니다.
// Retrieve AuthenticationCookie
var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (cookie == null) return;
FormsAuthenticationTicket ticket = null;
try {
ticket = FormsAuthentication.Decrypt(cookie.Value);
} catch (Exception decryptError) {
// Handle properly
}
if (ticket == null) return; // Not authorised
if (ticket.Expiration > DateTime.Now) {
Response.Redirect("SessionExpiredPage.aspx"); // Or do other stuff here
}
세션 종속성이 있는 사이트의 경우 global.asax에서 session start 이벤트를 사용하여 오래된 인증에서 로그아웃하기만 하면 됩니다.
void Session_Start(object sender, EventArgs e)
{
if (HttpContext.Current.Request.IsAuthenticated)
{
//old authentication, kill it
FormsAuthentication.SignOut();
//or use Response.Redirect to go to a different page
FormsAuthentication.RedirectToLoginPage("Session=Expired");
HttpContext.Current.Response.End();
}
}
이렇게 하면 새 세션 = 새 인증, 기간이 지정됩니다.
언급URL : https://stackoverflow.com/questions/1470777/forms-authentication-timeout-vs-session-timeout
반응형
'source' 카테고리의 다른 글
Spring Boot 화이트라벨 오류 페이지(type=Not Found, status=404) (0) | 2023.06.20 |
---|---|
vuex 스토어를 라벨 페이지로 가져오는 동안 예기치 않은 토큰 오류가 발생했습니다. (0) | 2023.06.20 |
CSS를 사용하여 텍스트 길이를 n줄로 제한 (0) | 2023.06.20 |
SecurityMockMvc 구성자를 찾을 수 없습니다. (0) | 2023.06.20 |
하위 프로세스를 사용하여 실시간 출력 가져오기 (0) | 2023.06.20 |