Classic ASP

ASP에서 session과 cookie 사용하기

최고관리자
2018.05.24 15:56 92,569 0

본문

쿠키값 저장하기

<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires=date+365 
%>



쿠키값 가져오기

<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>



쿠키값 삭제하기

<%
Response.Cookies("firstname").Expires=date-1
%>



ASP에서 세션은 별다른 시작 선언이 없어도 알아서 작동합니다.

Global.asa파일에 Session_OnStart 부분에 특정 구문을 입력해두면 세션시작시 항상 해당 구문을 수행하도록 설정할 수 있습니다.


세션 시간 설정하기

분단위 입니다.

<%
Session.Timeout=5
%>



세션 값 저장하기

<%
Session("username")="Donald Duck"
Session("age")=50

dim i
For Each i in Session.Contents
  Response.Write(i & "<br />")
Next
%>



세션 종료하기

<%
Session.Abandon
%>



세션값 출력하기

Welcome <%Response.Write(Session("username"))%>

다음과 같이 사용할수도 있습니다.

<%
If Session.Contents("age")<18 then
  Session.Contents.Remove("sale")
End If
%>


<%
dim i
dim j
j=Session.Contents.Count
Response.Write("Session variables: " & j)
For i=1 to j
  Response.Write(Session.Contents(i) & "<br />")
Next
%>



세션값 지우기

<%
Session.Contents.RemoveAll()
%>


출처: http://trend21c.tistory.com/1073 [나를 찾는 아이] 

댓글목록 0

등록된 댓글이 없습니다.