473,396 Members | 2,009 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,396 software developers and data experts.

Session Start / Application_BeginRequest Issues

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
3 18306
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Seth | last post by:
I have noticed that the id of my session object changes when I switch from a non-secure to a secure connection. What I'm trying to do: I have a cookie that is built on the non-secure side of...
2
by: francois | last post by:
Hi, I would like to redirect the user to the login page after the session time out. I tried to do a trick in the global.aspx.cs protected void Application_BeginRequest(Object sender,...
2
by: David Berman | last post by:
It seems that my site is losing session information when using Server.Transfer. I have a page called PictureGallery.aspx. It takes an argument which is an index id, so it would look like...
2
by: Stu | last post by:
Hi, I am trying to access session variable value from the 'Application_BeginRequest' handler in the global asax file but get the message - 'Session state not available in this context'. I have...
12
by: Thomas Andersson | last post by:
Hi, How can I access a session variable within a Public Class? I have tried the below code, but I get a server error "Object reference not set to an instance of an object". ...
1
by: Tim F | last post by:
I can not persist a Session across page changes. I have it configured as follows: * VS .NET 2002 * <pages buffer="true" enableSessionState="true" enableViewState="true"...
0
by: Greg | last post by:
I have an application that allows users to select one or more files to upload to the server. Each of the html file controls is stored in an array that is held in the session object. This allows...
25
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.