I saw some questions (Here and Here) but they do not answer my question. I am trying to call Ajax using "ajax.ashx" file, and in function to access Session. For some reason, the value of the Session object itself is null.
Use example:
Session = HttpContext.Current.Session // This is null
Or:
public virtual void ProcessRequest(HttpContext context) { System.Web.SessionState.HttpSessionState Session = context.Session; // This is null }
In the Web.config:
<sessionState timeout="1800"></sessionState>
Session will never be null if you have any variable in the Session. HttpContext. Current. Session represents a collection of all the session values that you are storing in the session.
What is an ASHX file? An ASHX file is a webpage that is used by the ASP.NET HTTP Handler to serve user with the pages that are referenced inside this file. The ASP.NET HTTP Handler processes the incoming request, references the pages from the . ashx file, and sends back the compiled page back to the user's browser.
For adding ashx file follow below steps. Right click on Project. Select Add from the menu. In Add New Item dialog window select Generic Handler and click on Add.
You must add on your handler the IRequiresSessionState
on the declaration of it as:
public class YourHandleName : IHttpHandler, IRequiresSessionState { ...
by default the handlers are not connected with the session to keep them minimum, by adding the IRequiresSessionState
you attach them with the session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With