Getting and Setting Session State in HttpHandlers (ASHX files)

If you just want to read your Session State from an ASHX or HttpHandler, you need to implement IReadOnlySessionState.  If you want to write to your Session State, you must implement IRequiresSessionState.  Note that you will also need use the System.Web.SessionState namespace.  This post describes getting and setting session state in HttpHandlers (ASHX files).

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

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

public class UploadFile : IHttpHandler, IRequiresSessionState
   public bool IsReusable { get { return true; } }
   public void ProcessRequest(HttpContext context)
       string ftpUsername = "ftpUser";
       context.Session["ftpUsername"] = ftpUsername;