Session object is NULL in HTTP handler

G

Guest

Hi,
I m new with aspnet. I am trying to do an application that writes the
session in a cookie but the context.session is null.

Here in the code, the cookieValue is allways without session, ...
I dont know how to get the session, maybe I cant...

thanks in advance

Miguel

The code is the following:

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;

public class SetIdentity : IHttpModule
{

public void Init(HttpApplication context)
{
context.EndRequest += (new
EventHandler(this.Application_AuthenticateRequest));
}

protected void Application_BeginRequest(object sender, EventArgs e){
}

private void Application_AuthenticateRequest(object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;

HttpSessionState session = context.Session;
String cookieValue = "without session";
if (session != null) cookieValue = session.SessionID;
// Put it into a cookie
HttpCookie hc = new
HttpCookie("SessionSharePoint", cookieValue);
hc.Expires = DateTime.New.AddMinutes(20);


// Add it to the cookies collection
context.Response.Cookies.Add(hc);


}
public void Dispose()
{
}


}
 
L

Lucas Tam

I m new with aspnet. I am trying to do an application that writes the
session in a cookie but the context.session is null.

Q: I am writing my own HttpHandler. Why is session state not working?
A: Your HttpHandler has to implement the "marker" interface
IRequiresSessionState or IReadOnlySessionState in order to use session
state.
 
G

Guest

thanks!
I will see how to do it.
Do I have to add new methods? Well, I'll take a look

thank you

Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top