473,796 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session object is NULL in HTTPModule

ey,
I m trying to make a new httpmodule but the session object is null. I m
implementing IReadOnlySessio nState but it keep on being null.

I m novice in this enviroment, does anybody know what's happening?

thanks

Miguel
Nov 19 '05 #1
5 7312
It's likely a timing issue. Session isn't available until the
AcquireRequestS tate event.

Try hooking after this, such as the PreRequestHandl erExecute event

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:A9******** *************** ***********@mic rosoft.com...
ey,
I m trying to make a new httpmodule but the session object is null. I m
implementing IReadOnlySessio nState but it keep on being null.

I m novice in this enviroment, does anybody know what's happening?

thanks

Miguel

Nov 19 '05 #2
thank you karl,

buff, it doesn't work, I think I am doing what you have said but I dont get
the session: context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));.

any ideas? I am a little bit lost :-(

thanks again

here is the source code:

public class SetIdentity : IHttpModule, IReadOnlySessio nState
{
public void Init(HttpApplic ation context)
{
context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));
}

private void Application_Aut henticateReques t(object source, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)source;

HttpContext context = application.Con text;
HttpSessionStat e session = context.Session ;

String cookieValue = "No session";
if (session != null) cookieValue = session.Session ID;
// Put it into a cookie
HttpCookie hc = new
HttpCookie("Ses sionSharePoint" , cookieValue);
hc.Expires = DateTime.Now.Ad dMinutes(20);

// Add it to the cookies collection
context.Respons e.Cookies.Add(h c);
}
public void Dispose()
{
}
}
"Karl Seguin" wrote:
It's likely a timing issue. Session isn't available until the
AcquireRequestS tate event.

Try hooking after this, such as the PreRequestHandl erExecute event

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:A9******** *************** ***********@mic rosoft.com...
ey,
I m trying to make a new httpmodule but the session object is null. I m
implementing IReadOnlySessio nState but it keep on being null.

I m novice in this enviroment, does anybody know what's happening?

thanks

Miguel


Nov 19 '05 #3
Your code works fine for me. session isn't null and cookie was being set...

I'm not the only one recommending my approach:
http://channel9.msdn.com/ShowPost.aspx?PostID=1498

but, you don't seem to be the only one having problems:
http://weblogs.asp.net/acampbell/arc...08/277929.aspx

Perhaps you can contact Alex and see if he ever solved his problem?

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
thank you karl,

buff, it doesn't work, I think I am doing what you have said but I dont
get
the session: context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));.

any ideas? I am a little bit lost :-(

thanks again

here is the source code:

public class SetIdentity : IHttpModule, IReadOnlySessio nState
{
public void Init(HttpApplic ation context)
{
context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));
}

private void Application_Aut henticateReques t(object source, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)source;

HttpContext context = application.Con text;
HttpSessionStat e session = context.Session ;

String cookieValue = "No session";
if (session != null) cookieValue = session.Session ID;
// Put it into a cookie
HttpCookie hc = new
HttpCookie("Ses sionSharePoint" , cookieValue);
hc.Expires = DateTime.Now.Ad dMinutes(20);

// Add it to the cookies collection
context.Respons e.Cookies.Add(h c);
}
public void Dispose()
{
}
}
"Karl Seguin" wrote:
It's likely a timing issue. Session isn't available until the
AcquireRequestS tate event.

Try hooking after this, such as the PreRequestHandl erExecute event

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:A9******** *************** ***********@mic rosoft.com...
> ey,
> I m trying to make a new httpmodule but the session object is null. I m
> implementing IReadOnlySessio nState but it keep on being null.
>
> I m novice in this enviroment, does anybody know what's happening?
>
> thanks
>
> Miguel


Nov 19 '05 #4
thanks, really helpfull.
The problem seems not to be easy.

cheers

Miguel

"Karl Seguin" wrote:
Your code works fine for me. session isn't null and cookie was being set...

I'm not the only one recommending my approach:
http://channel9.msdn.com/ShowPost.aspx?PostID=1498

but, you don't seem to be the only one having problems:
http://weblogs.asp.net/acampbell/arc...08/277929.aspx

Perhaps you can contact Alex and see if he ever solved his problem?

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
thank you karl,

buff, it doesn't work, I think I am doing what you have said but I dont
get
the session: context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));.

any ideas? I am a little bit lost :-(

thanks again

here is the source code:

public class SetIdentity : IHttpModule, IReadOnlySessio nState
{
public void Init(HttpApplic ation context)
{
context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));
}

private void Application_Aut henticateReques t(object source, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)source;

HttpContext context = application.Con text;
HttpSessionStat e session = context.Session ;

String cookieValue = "No session";
if (session != null) cookieValue = session.Session ID;
// Put it into a cookie
HttpCookie hc = new
HttpCookie("Ses sionSharePoint" , cookieValue);
hc.Expires = DateTime.Now.Ad dMinutes(20);

// Add it to the cookies collection
context.Respons e.Cookies.Add(h c);
}
public void Dispose()
{
}
}
"Karl Seguin" wrote:
It's likely a timing issue. Session isn't available until the
AcquireRequestS tate event.

Try hooking after this, such as the PreRequestHandl erExecute event

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:A9******** *************** ***********@mic rosoft.com...
> ey,
> I m trying to make a new httpmodule but the session object is null. I m
> implementing IReadOnlySessio nState but it keep on being null.
>
> I m novice in this enviroment, does anybody know what's happening?
>
> thanks
>
> Miguel


Nov 19 '05 #5
ey karl!

Know it is working. It was a problem with the web.config. There is a
parameter to false that must be true and a comment module in charge of the
sessionState.

Thank you

miguel

"Karl Seguin" wrote:
Your code works fine for me. session isn't null and cookie was being set...

I'm not the only one recommending my approach:
http://channel9.msdn.com/ShowPost.aspx?PostID=1498

but, you don't seem to be the only one having problems:
http://weblogs.asp.net/acampbell/arc...08/277929.aspx

Perhaps you can contact Alex and see if he ever solved his problem?

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
thank you karl,

buff, it doesn't work, I think I am doing what you have said but I dont
get
the session: context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));.

any ideas? I am a little bit lost :-(

thanks again

here is the source code:

public class SetIdentity : IHttpModule, IReadOnlySessio nState
{
public void Init(HttpApplic ation context)
{
context.PreRequ estHandlerExecu te += (new EventHandler
this.Applicatio n_AuthenticateR equest));
}

private void Application_Aut henticateReques t(object source, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)source;

HttpContext context = application.Con text;
HttpSessionStat e session = context.Session ;

String cookieValue = "No session";
if (session != null) cookieValue = session.Session ID;
// Put it into a cookie
HttpCookie hc = new
HttpCookie("Ses sionSharePoint" , cookieValue);
hc.Expires = DateTime.Now.Ad dMinutes(20);

// Add it to the cookies collection
context.Respons e.Cookies.Add(h c);
}
public void Dispose()
{
}
}
"Karl Seguin" wrote:
It's likely a timing issue. Session isn't available until the
AcquireRequestS tate event.

Try hooking after this, such as the PreRequestHandl erExecute event

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Miguel" <Mi****@discuss ions.microsoft. com> wrote in message
news:A9******** *************** ***********@mic rosoft.com...
> ey,
> I m trying to make a new httpmodule but the session object is null. I m
> implementing IReadOnlySessio nState but it keep on being null.
>
> I m novice in this enviroment, does anybody know what's happening?
>
> thanks
>
> Miguel


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10856
by: LL | last post by:
Hi, Where is the best place to check the session's object, if it's null, then redirect the user to login page? put into every page's load event? Thanks.
2
4064
by: shland | last post by:
Hi - I have a page in which I'm using session variables... The first time someone goes to the page, obviously the session objects are null. But the user can return to the page, at which time the session objects won't be null. On initializing the page, what's the syntax to check to see if the session object is null before trying to access it? I did search the msdn help, but I'm not finding exactly what I need here. - Using C#. ...
4
5051
by: Jeremy Lew | last post by:
When my HttpHandler is processing a request when installed on a particular 2003 Server machine, the Context.Session object is null. Any idea why this might be? My handler implements IRequiresSessionState and works normally on other machines. Thanks, Jeremy
4
1329
by: Tony | last post by:
how do I check if the data in the session object is null before extracting it. The following throws an error if the Session object has not already been created. string str = System.Web.HttpContext.Current.Session.ToString(); Thanks
3
9588
by: Miguel | last post by:
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
3
1668
by: ESmith | last post by:
I have multi-page form where I pass an object between pages as follows: On each page: // What page to go to next private void btnContinue_Click(object sender, System.EventArgs e) { if (Page.IsValid) { MyXferObj obj = new MyXferObj();
3
2509
by: JebBushell | last post by:
Here's my code: private void Page_Load(object sender, System.EventArgs e) { clientId = Session.ToString(); .... etc. It bombs on the assignment after the session has timed out (System.NullReferenceException: Object reference not set to an instance of an object). I don't understand why it is processing the page load event at all.
3
3359
by: Jan Kucera | last post by:
Hi, why is session object null if the ashx file is requested? How can I force to create session when the request is to custom handler? Thanks, Jan
3
2820
by: Benton | last post by:
Hi there, Currently I have a rather simple class with a few members: string userName; string password; string centers; bool canModify; I have correspondant GET properties for them in the class. I need to store
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.