posted by 방랑군 2012. 1. 7. 20:55

출처 :  http://blog.naver.com/PostView.nhn?blogId=inidu2&logNo=110077631974&categoryNo=0&parentCategoryNo=33&viewDate=&currentPage=2&postListTopCurrentPage=1&userTopListOpen=true&userTopListCount=10&userTopListManageOpen=false&userTopListCurrentPage=2

닷넷에서 jquery를 사용 $.post() 사용하여 ajax로 처리를 하는데 ashx에서 세션 생성이 안되고 읽기만 가능하도록 되어 있어서 한참 동안 삽질.

네이년에도 안나와서 구글 찾아보니 나온다.

 

 

A reminder to myself and others, when you want to get access to your Session State from an ASHX or HttpHandler, you need to implement IReadOnlySessionState:

<% @ webhandler language="C#" class="DownloadHandler" %>

using System;
using System.Web;
using System.Web.SessionState;

public class DownloadHandler : IHttpHandler, IReadOnlySessionState
{
   public bool IsReusable { get { return true; } }
   
   public void ProcessRequest(HttpContext ctx)
   {
       ctx.Response.Write(ctx.Session["fred"]);
   }
}

 

세션을 사용하려면 IReadOnlySessionState, IRequiresSessionState 를 써야 한다.

 

원문 : http://www.hanselman.com/blog/GettingSessionStateInHttpHandlersASHXFiles.aspx