473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Session unavailable in PostAcquireRequestState/PreRequestHandlerExecute

Hi all, I'm tearing my hair out here and I'm desperately hoping someone
has a fix.

I've got a .Net 2.0 web service for which I need session state, I can't
use cookies because I'm using the .NetCF, I used a cookieless session
and that was fine over Wi-Fi but borked horribly over GPRS, for which I
blame the ISP.

I implemented a quick hack with a SoapHeader containing the SessionId
and implemented a custom ISessionIDManager, now I just want to get some
data back out.

For reasons I'm unable to fathom, HttpContext.Session is unavailable
during PreRequestHandlerExecute. Even more bizarrely, the session is
unavailable during PostAcquireRequestState, the event that fires to
tell you that the session has been populated.

This issue affects .asmx and .axd files, but NOT aspx. The issue has
been raised before in posts going back (at least) to 2002 under the 1.0
framework.

The WebMethods involved all have EnableSession set to true and I can
access the session from the actual webservice, just not from any
application events that fire beforehand.

Does anybody have a workaround for this? I suppose I could drop the
session altogether and use the Application Cache to store a user's
credentials, but that's uglier than ugliness.

<code>

public class AuthenticateRequestHttpModule : IHttpModule
{
private HttpApplication _HttpApp;

public void Init(HttpApplication httpApp)
{
this._HttpApp = httpApp;
_HttpApp.PostAcquireRequestState+= new
EventHandler(AuthenticateFromSession);
}

protected void AuthenticateFromSession(object sender, EventArgs
e)
{
HttpContext context = (sender as HttpApplication).Context;
if(null == context.Session)
throw new Exception("Isn't this a _really_ silly bug?");
}

public void Dispose(){}

}

</code>

Feb 10 '06 #1
1 3253
Added the IRequiresSessionState marker interface. For some reason,
this seems to be required for non-aspx files in HttpModules, though it
worked without if I was access a web page.

I'd tried this before, but must have been handling an event too early
in the request lifecycle.

Feb 13 '06 #2

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

Similar topics

3
by: Rolf Gossen | last post by:
Hello NG, In my Web-Application I want to redirect the User to the Login-Page whenever his Session has timed out. According to a lot of NewsGroup Entries this can be achieved by the following...
0
by: matt | last post by:
I've come across a real problem and am totally stuck as to why this is happening, hoping desperately that someone else has experienced the same thing, and knows a solution! Session state should be...
0
by: kat | last post by:
Hi, I have written an HTTPModule that calls functions from a DLL using PInvoke. I am only registering for a couple events, and they are BeginRequest, PreRequestHandlerExecute, and EndRequest. ...
0
by: themattconnolly | last post by:
I have an application built on virtual pages, where the url is intercepted and a different page is built according to the url. In order to also use forms authentication, I had a Server.Transfer...
5
by: Miguel | last post by:
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...
3
by: rony_16 | last post by:
hi , i want to override the object session in class page , because i want to check the Session automaticly in WebForm , without writing "if" in evry page . i know that i need to make a new...
3
by: kingski | last post by:
I have a web site created with ASP.NET 1.1. availability Global.asax: protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
1
by: Jonathan Wood | last post by:
I was experimenting with putting code in the Application_AuthenticateRequest hander. I called some static code and found that HttpContext.Current.Session was null! Is this yet another...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app. When session is invalid, how to redirect user to the login page? I don't want to add the code to redirect user to the login page into every page. Thanks, -Billy
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.