如果在 ashx 裡面直接使用 session["acc"].tostring(),
會出現「編譯器錯誤訊息: CS0103: 名稱 'Session' 不存在於目前內容中」,
使用 HttpContext.Current.Session["acc"].tostring(),
則會出現「例外詳細資訊: System.NullReferenceException: 並未將物件參考設定為物件的執行個體」
這個時候需要在 class 名稱後面加上 「 , System.Web.SessionState.IRequiresSessionState」

public class S_0_2014F : IHttpHandler , System.Web.SessionState.IRequiresSessionState
{
  //內容
    public void ProcessRequest(HttpContext context)
    {
         string vTmp = context.Session["acc"].ToString();
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}
文章標籤
全站熱搜