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.NullRef erenceException : Object reference not set to an instance of an object"
*************** *************** ************
protected void Session_Start(O bject sender, EventArgs e)
{
System.Uri refURL = Context.Request .UrlReferrer;
if(refURL != null)
{
Context.Session .Add("referingU RL", refURL.ToString ());
}
}
protected void Application_Beg inRequest(Objec t sender, EventArgs e)
{
string refPage = Context.Request .QueryString.Ge t("Page");
if(refPage != null)
{
Context.Session .Add("referingP age", refPage.ToStrin g());
}
}
*************** *************** ************
Does anyone know what I'm doing wrong?
Thanks in advance for your help! 3 18323
On Sun, 4 Jul 2004 10:08:01 -0700, Paul Daly <Paul Daly
(MCP)@discussio ns.microsoft.co m> 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.NullRef erenceException : Object reference not set to an instance of an object"
*************** *************** ************ protected void Session_Start(O bject sender, EventArgs e) { System.Uri refURL = Context.Request .UrlReferrer; if(refURL != null) { Context.Session .Add("referingU RL", refURL.ToString ()); } } protected void Application_Beg inRequest(Objec t sender, EventArgs e) { string refPage = Context.Request .QueryString.Ge t("Page"); if(refPage != null) { Context.Session .Add("referingP age", refPage.ToStrin g()); } } *************** *************** ************
Does anyone know what I'm doing wrong?
Thanks in advance for your help!
Which one is erroring out? Application_Beg inRequest 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_Pre RequestHandlerE xecute
and Application_Acq uireRequestStat e
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
It errors out on Application_Beg inRequest.
Are you suggesting that I move the code from Session_Start to Application_Acq uireRequestStat e and from Application_Beg inRequest to Application_Pre RequestHandlerE xecute?
Also.. where can I find a complete listing of all of the events that occur during the lifecycle of a web application including Application_Pre RequestHandlerE xecute
and Application_Acq uireRequestStat e?
Thank you for your help.
"Craig Deelsnyder" wrote: On Sun, 4 Jul 2004 10:08:01 -0700, Paul Daly <Paul Daly (MCP)@discussio ns.microsoft.co m> 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.NullRef erenceException : Object reference not set to an instance of an object"
*************** *************** ************ protected void Session_Start(O bject sender, EventArgs e) { System.Uri refURL = Context.Request .UrlReferrer; if(refURL != null) { Context.Session .Add("referingU RL", refURL.ToString ()); } } protected void Application_Beg inRequest(Objec t sender, EventArgs e) { string refPage = Context.Request .QueryString.Ge t("Page"); if(refPage != null) { Context.Session .Add("referingP age", refPage.ToStrin g()); } } *************** *************** ************
Does anyone know what I'm doing wrong?
Thanks in advance for your help!
Which one is erroring out? Application_Beg inRequest 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_Pre RequestHandlerE xecute and Application_Acq uireRequestStat e
-- Craig Deelsnyder Microsoft MVP - ASP/ASP.NET
On Sun, 4 Jul 2004 10:58:01 -0700, Paul Daly
<Pa*********@di scussions.micro soft.com> wrote: It errors out on Application_Beg inRequest.
Are you suggesting that I move the code from Session_Start to Application_Acq uireRequestStat e and from Application_Beg inRequest to Application_Pre RequestHandlerE xecute?
Also.. where can I find a complete listing of all of the events that occur during the lifecycle of a web application including Application_Pre RequestHandlerE xecute and Application_Acq uireRequestStat e?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
things. What I need to do is to switch to a secure
connection and then later on while still in that secure
connection delete the cookie that was...
|
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, EventArgs e)
{
|
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
PictureGallery.aspx?id=30 to display gallery 30. In this way I have a
database driven picture gallery. To improve indexing, I put code in
Global.asax to...
|
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 tried
loading the current context using 'Dim context As HttpContext =
HttpContext.Current' but get the error 'Object reference not set to an...
|
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".
System.Web.HttpContext.Current.Session.Add("myKey", "myValue")
Dim a As String
a = System.Web.HttpContext.Current.Session.Item("myKey")
| |
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"
enableViewStateMac="true" autoEventWireup="true"/>
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" stateNetworkTimeout="10"
|
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 the user to
select all the files they need to upload at once before clicking the
upload button. However, the users want a warning to appear if there...
|
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
|
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);
HttpContext.Current.Session = DateTime.Now;
For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |