By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

Session Start / Application_BeginRequest Issues

P: n/a
I'm trying to write a log file that captures the referring url if the request is a new session, and captures a querystring value if the user is browsing between pages on the website.

When using the code below, I get the following error...

"System.NullReferenceException: Object reference not set to an instance of an object"

******************************************
protected void Session_Start(Object sender, EventArgs e)
{
System.Uri refURL = Context.Request.UrlReferrer;
if(refURL != null)
{
Context.Session.Add("referingURL", refURL.ToString());
}
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string refPage = Context.Request.QueryString.Get("Page");
if(refPage != null)
{
Context.Session.Add("referingPage", refPage.ToString());
}
}
******************************************

Does anyone know what I'm doing wrong?

Thanks in advance for your help!
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 4 Jul 2004 10:08:01 -0700, Paul Daly <Paul Daly
(MCP)@discussions.microsoft.com> wrote:
I'm trying to write a log file that captures the referring url if the
request is a new session, and captures a querystring value if the user
is browsing between pages on the website.

When using the code below, I get the following error...

"System.NullReferenceException: Object reference not set to an instance
of an object"

******************************************
protected void Session_Start(Object sender, EventArgs e)
{
System.Uri refURL = Context.Request.UrlReferrer;
if(refURL != null)
{
Context.Session.Add("referingURL", refURL.ToString());
}
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string refPage = Context.Request.QueryString.Get("Page");
if(refPage != null)
{
Context.Session.Add("referingPage", refPage.ToString());
}
}
******************************************

Does anyone know what I'm doing wrong?

Thanks in advance for your help!


Which one is erroring out? Application_BeginRequest is the first 'event'
in the chain, it's so early that Session is not available in it, so that
will get you in trouble there.

Also, I believe in Session_Start the Context still doesn't have a
reference to the Session, so unfortunately you're out of luck there as
well.

Others have said you can access it in Application_PreRequestHandlerExecute
and Application_AcquireRequestState

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2

P: n/a
It errors out on Application_BeginRequest.

Are you suggesting that I move the code from Session_Start to Application_AcquireRequestState and from Application_BeginRequest to Application_PreRequestHandlerExecute?

Also.. where can I find a complete listing of all of the events that occur during the lifecycle of a web application including Application_PreRequestHandlerExecute
and Application_AcquireRequestState?

Thank you for your help.

"Craig Deelsnyder" wrote:
On Sun, 4 Jul 2004 10:08:01 -0700, Paul Daly <Paul Daly
(MCP)@discussions.microsoft.com> wrote:
I'm trying to write a log file that captures the referring url if the
request is a new session, and captures a querystring value if the user
is browsing between pages on the website.

When using the code below, I get the following error...

"System.NullReferenceException: Object reference not set to an instance
of an object"

******************************************
protected void Session_Start(Object sender, EventArgs e)
{
System.Uri refURL = Context.Request.UrlReferrer;
if(refURL != null)
{
Context.Session.Add("referingURL", refURL.ToString());
}
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string refPage = Context.Request.QueryString.Get("Page");
if(refPage != null)
{
Context.Session.Add("referingPage", refPage.ToString());
}
}
******************************************

Does anyone know what I'm doing wrong?

Thanks in advance for your help!


Which one is erroring out? Application_BeginRequest is the first 'event'
in the chain, it's so early that Session is not available in it, so that
will get you in trouble there.

Also, I believe in Session_Start the Context still doesn't have a
reference to the Session, so unfortunately you're out of luck there as
well.

Others have said you can access it in Application_PreRequestHandlerExecute
and Application_AcquireRequestState

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3

P: n/a
On Sun, 4 Jul 2004 10:58:01 -0700, Paul Daly
<Pa*********@discussions.microsoft.com> wrote:
It errors out on Application_BeginRequest.

Are you suggesting that I move the code from Session_Start to
Application_AcquireRequestState and from Application_BeginRequest to
Application_PreRequestHandlerExecute?

Also.. where can I find a complete listing of all of the events that
occur during the lifecycle of a web application including
Application_PreRequestHandlerExecute
and Application_AcquireRequestState?

Thank you for your help.


Some more info:

http://support.microsoft.com/default...n-us;Q312607#2

Actually, I think my statement before was incorrect; been awhile since I
looked at this myself, but in Session you should be able to see the
Session object, makes sense, see the example here:

http://samples.gotdotnet.com/quickst...eoverview.aspx

Sorry for the confusion...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.