Your strategic advantage starts here

Getting and Setting Session State in HttpHandlers (ASHX files)

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;
   }
}

 

Related Posts
Leave a Reply
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day