Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Saturday, March 31, 2012

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

}

</codeAdded 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.

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>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.

Tuesday, March 13, 2012

Session variables are lost

we have a session variable object that gets lost in the same event call.
I have windows XP Pro as my os with the latest service pack...
I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
does not work for me...

Here is what my machine.config looks like:

<sessionState mode="InProc" cookieless="true" timeout="20"/
Any help is appreciated...

Thanks
Guns
www.goondemand.comGuns,

Does the web.config file get changed? Probably because of a virus scanner?
Or do you prob. have another file in your bin directory which is changed
during execution or another configuration file or an access database?

If so you know why your application will restart and (because you save the
session InProc) looses your session.

Greetings

Daniel

"Guns" <gg@.ecokard.com> schrieb im Newsbeitrag
news:ub%23UABeiFHA.1412@.TK2MSFTNGP09.phx.gbl...
> we have a session variable object that gets lost in the same event call.
> I have windows XP Pro as my os with the latest service pack...
> I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
> does not work for me...
> Here is what my machine.config looks like:
> <sessionState mode="InProc" cookieless="true" timeout="20"/>
> Any help is appreciated...
> Thanks
> Guns
> www.goondemand.com
>
Try instead of "InProc" this:

<sessionState
mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
stateNetworkTimeout="10"
sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
cookieless="false"
timeout="20"
/
And run the "ASP.NET State Server Service" in Services...

I had the same problem of ramdomly disappearing/reappearing
session-values... Not it works fine.

"Guns" <gg@.ecokard.com> schrieb im Newsbeitrag
news:ub%23UABeiFHA.1412@.TK2MSFTNGP09.phx.gbl...
> we have a session variable object that gets lost in the same event call.
> I have windows XP Pro as my os with the latest service pack...
> I have the .net 1.1 SP1 installed. Even tried installing 1.0 SP2 but that
> does not work for me...
> Here is what my machine.config looks like:
> <sessionState mode="InProc" cookieless="true" timeout="20"/>
> Any help is appreciated...
> Thanks
> Guns
> www.goondemand.com
>