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()
{
}
}
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()
{
}
}