Session object is NULL in HTTPModule

G

Guest

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

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

thanks

Miguel
 
K

Karl Seguin

It's likely a timing issue. Session isn't available until the
AcquireRequestState event.

Try hooking after this, such as the PreRequestHandlerExecute event

Karl
 
G

Guest

thank you karl,

buff, it doesn't work, I think I am doing what you have said but I dont get
the session: context.PreRequestHandlerExecute += (new EventHandler
this.Application_AuthenticateRequest));.

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

thanks again

here is the source code:

public class SetIdentity : IHttpModule, IReadOnlySessionState
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += (new EventHandler
this.Application_AuthenticateRequest));
}

private void Application_AuthenticateRequest(object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;

HttpContext context = application.Context;
HttpSessionState session = context.Session;

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

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


}
public void Dispose()
{
}


}
 
K

Karl Seguin

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/archive/2004/12/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!)
 
G

Guest

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
 
Joined
Oct 27, 2006
Messages
1
Reaction score
0
Web.config

Hi Miguel,
I know this post was from a while back, but I'm having the same exact issue. What were the lines in the web.config that you changed? Thanks for the clarification!

-argon
 
Joined
Aug 23, 2010
Messages
1
Reaction score
0
this kind ofthing I think:

<httpModules>
<add name="DaoFactoryProvider" type="Capture.DaoProvider.DaoFactoryProvider"/>
</httpModules>
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top