Connect with Expertise | Find Experts, Get Answers, Share Insights

Session object is NULL in HTTP handler

Miguel
 
Posts: n/a
#1: Nov 19 '05
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()
{
}


}


Lucas Tam
 
Posts: n/a
#2: Nov 19 '05

re: Session object is NULL in HTTP handler


=?Utf-8?B?TWlndWVs?= <Miguel@discussions.microsoft.com> wrote in
news:ABA4EBBF-0096-48EB-9FD4-BCA99528E8A9@microsoft.com:
[color=blue]
> 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.
>[/color]

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.

--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Miguel
 
Posts: n/a
#3: Nov 19 '05

re: Session object is NULL in HTTP handler


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

thank you

Miguel



"Lucas Tam" wrote:
[color=blue]
> =?Utf-8?B?TWlndWVs?= <Miguel@discussions.microsoft.com> wrote in
> news:ABA4EBBF-0096-48EB-9FD4-BCA99528E8A9@microsoft.com:
>[color=green]
> > 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.
> >[/color]
>
> 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.
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/
>[/color]
Lucas Tam
 
Posts: n/a
#4: Nov 19 '05

re: Session object is NULL in HTTP handler


=?Utf-8?B?TWlndWVs?= <Miguel@discussions.microsoft.com> wrote in
news:1AAEA950-AE63-4321-A63D-F7B42E14739D@microsoft.com:
[color=blue]
> thanks!
> I will see how to do it.
> Do I have to add new methods? Well, I'll take a look[/color]


Nope, you just inherit the classes... that's all : )


--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Closed Thread