Greetings
I am writing code in a C# web service solution.
I want to create an instance of an object (that I created) in a
Session variable. I need to check to see if the Session variable has
been set yet. If the variable already contains an instance of this
object then I will retrieve and use the existing object, rather than
create a new instance. ie. I will only create a new object the first
time the procedure is called, and then save it for the next time.
So, in an article I found in my MSDN help entitled
"Code: Reading Values From Session State (Visual C#)"
the procedure recommended to check to see if the Session var was set
yet, is this:
if (Session["SomeVarNam e"] == null)
When I do this, I get the
"Object reference not set to an instance of an object" error.
Checking in debug, I see that "Session" is not defined.
I thought Session was supposed to be created first thing when a page
is accessed. So, how come mine is not defined yet?
Could it be because it is an .asmx file rather than an aspx file?
If asmx pages don't create a Session object, is there a way to
maintain session information in a web service?
Thanks much
Jeff 2 3140
To be more specific in reference to: Checking in debug, I see that "Session" is not defined.
Breaking on this line :if (Session["SomeVarNam e"] == null)
and pointing to the word Session, The following information pops up:
Session = <undefined value>
Thanks again
Jeff
On Mon, 07 Nov 2005 05:18:43 GMT, Jeff User <je*******@hotm ail.com>
wrote:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has been set yet. If the variable already contains an instance of this object then I will retrieve and use the existing object, rather than create a new instance. ie. I will only create a new object the first time the procedure is called, and then save it for the next time.
So, in an article I found in my MSDN help entitled "Code: Reading Values From Session State (Visual C#)" the procedure recommended to check to see if the Session var was set yet, is this: if (Session["SomeVarNam e"] == null)
When I do this, I get the "Object reference not set to an instance of an object" error. Checking in debug, I see that "Session" is not defined.
I thought Session was supposed to be created first thing when a page is accessed. So, how come mine is not defined yet?
Could it be because it is an .asmx file rather than an aspx file?
If asmx pages don't create a Session object, is there a way to maintain session information in a web service?
Thanks much Jeff
Greetings all
In addition to an article that John Timney suggested: http://msdn.microsoft.com/library/de...ce08062002.asp
I would also recommend this article: http://support.microsoft.com/default...b;en-us;816637
The first article got me 3/4 of the way there.
The 2nd article listed here includes saving the cookie on the client
side for use on the next call to the server.
Thanks again John for giving me the good start that I needed.
Jeff
On Mon, 07 Nov 2005 05:43:39 GMT, Jeff User <je*******@hotm ail.com>
wrote: To be more specific in reference to:Checking in debug, I see that "Session" is not defined.
Breaking on this line :if (Session["SomeVarNam e"] == null) and pointing to the word Session, The following information pops up: Session = <undefined value>
Thanks again Jeff
On Mon, 07 Nov 2005 05:18:43 GMT, Jeff User <je*******@hotm ail.com> wrote:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has been set yet. If the variable already contains an instance of this object then I will retrieve and use the existing object, rather than create a new instance. ie. I will only create a new object the first time the procedure is called, and then save it for the next time.
So, in an article I found in my MSDN help entitled "Code: Reading Values From Session State (Visual C#)" the procedure recommended to check to see if the Session var was set yet, is this: if (Session["SomeVarNam e"] == null)
When I do this, I get the "Object reference not set to an instance of an object" error. Checking in debug, I see that "Session" is not defined.
I thought Session was supposed to be created first thing when a page is accessed. So, how come mine is not defined yet?
Could it be because it is an .asmx file rather than an aspx file?
If asmx pages don't create a Session object, is there a way to maintain session information in a web service?
Thanks much Jeff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shelly |
last post by:
I set a session variable on error in the login page and then call the login
page again. I test on that session variable but it shows as not set. I
checked with an echo immediately after setting the error session variable so
I am 100% positive that it is set. The recursive entry to the login page
echos a message that the error session variable is unset.
Any clues?
Here is the setting code and the testing code (commented out)"...
|
by: Nick Jushchyshyn |
last post by:
Having a really strange issue with IIS 6 where the session variable does not
stay consistant. The first symptom was that database connections (which use a
user entered name/PW stored in the Session) in ASP pages were failing.
Finally got to (what I think is) the root issue by creating two ASP pages,
one that sets Session("test") = "Hello", and the other simply displays "Test
word: .." and the content of Session("test"). After visiting the...
|
by: Neil Jarman |
last post by:
Hi,
I need to create an array with a session variable.
According to thebook I'm using, the following should work, but if fails:
for each key in request.QueryString
if left(key,6) = "cboRun" then
iIndex = cint(mid (key,7))
response.Write(iIndex & "<br>")
|
by: Marc Rivait |
last post by:
Here is a very interesting scenario.
I have a simple test application that loads a page and sets a session
variable on the load event. On the first page there is a link to a second
page. The load event of the second page displays the value of the session
variable.
The problem is that when I use a W2k machine, this little test works
perfect. Session variable value is displayed on the second page. However,
when I use my XPPro...
|
by: Joe Molloy |
last post by:
Hi,
This isn't a mission critical question but I thought I'dl throw it out there
for your feedback as it's a bit curious.
I have developed a shopping cart for an application I'm working on which is
loosely based on the e-commerce example in the quickstarts tutorial.
In the cart display I have provided functionality so that when a user clicks
on a product name a popup is opened with the full product details displayed.
| |
by: moondaddy |
last post by:
I need to set a variable to a session variable (if that's what you call it)
like this:
dim ds as dataset = HttpContext.Current.Session("CustDataSet")
But I get an exception if this variable in the current session hasn't been
set yet so I need to test it. I tried:
If HttpContext.Current.Session("CustDataSet") = nothing then
HttpContext.Current.Session("CustDataSet") = GetCustDataSet()
|
by: N. Demos |
last post by:
Hello,
I'm learning ASP.NET, and am having a strange problem with some example
code from the book I'm using. The code increments and displays the value
stored in a session variable when the "Add" button is clicked. In
addition, the session variable is reset to zero when the "Empty" button
is pressed.
The problem is if the value is non-zero and the page is reloaded the
value is incremented. It appears as if the "Add" onClick event...
|
by: lwoods |
last post by:
I am trying to pass some info to another page on my site. I set
"session_start()" in page 1, assign a session variable to a value, then
execute a "header('Location: ....')." But on the target page I don't get
any session variable values! BTW, I used a relative location in the
Location header, not an absolute URL. The behavior looks like it started
another session, but it should not have.
Ideas?
TIA,
|
by: Adam J Knight |
last post by:
Hi all,
I am trying to test to see if a Session variable exists.
This was my initial attempt, and doesn't work
int intInstructorID = (Session.ToString() == null ?
Convert.ToInt32(Request.QueryString):
Convert.ToInt32(Session));
|
by: garks |
last post by:
I am the newbie in php
I have a problem about the session variable
When I create the session and session variable,
the variable is set in page 1, but in page 2 the variable is unset
and I don't know why.
I have searched a lot of tutorial, I followed all the steps but still
not work
Can anybody help me!!~
Thank you in advanced
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |