An ASPX page has the following code:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (IsNothing(Requ est.Cookies("Au thCookie"))) Then
Response.Write( Request.Cookies ("AuthCookie"). Value)
Else
Response.Write( Cookie 'AuthCookie' Doesn't Exist!)
End If
End Sub
Assume that the cookie named "AuthCookie " doesn't exist. As expected,
the Response.Write line in the Else condition gets rendered but if I
change the If condition to
If Not (IsNothing(Requ est.Cookies("Au thCookie").Valu e)) Then
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
Why? Is it because Request.Cookies ("AuthCookie"). Value evaluates to an
expression?
Thanks,
Arpan 3 2460
This throws an error because you can't access a property of an object that
doesn't exist. Value is a property, but since the object itself doesn't
exist there cannot be any property for it. You always have to test to see if
the object exists first, which is what you are doing initially, and only
after you test to see if the object itself exists can you attempt to access
a value.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage
"Arpan" <ar******@hotma il.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
An ASPX page has the following code:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (IsNothing(Requ est.Cookies("Au thCookie"))) Then
Response.Write( Request.Cookies ("AuthCookie"). Value)
Else
Response.Write( Cookie 'AuthCookie' Doesn't Exist!)
End If
End Sub
Assume that the cookie named "AuthCookie " doesn't exist. As expected,
the Response.Write line in the Else condition gets rendered but if I
change the If condition to
If Not (IsNothing(Requ est.Cookies("Au thCookie").Valu e)) Then
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
Why? Is it because Request.Cookies ("AuthCookie"). Value evaluates to an
expression?
Thanks,
Arpan
Thanks, Mark....your explanation has indeed been very very helpful.
One more question please - to test the existence of an object, I can
use "IsNothing" (as I did in post #1) & also "Is Nothing" like
If (Request.Cookie s("AuthCookie ") Is Nothing) Then
What I would like to know is are there any performance benefits of one
over the other? Or any other differences between "IsNothing" & "Is
Nothing"? Which among the 2 is more recommended?
Thanks once again,
Regards,
Arpan
Mark Fitzpatrick wrote:
This throws an error because you can't access a property of an object that
doesn't exist. Value is a property, but since the object itself doesn't
exist there cannot be any property for it. You always have to test to see if
the object exists first, which is what you are doing initially, and only
after you test to see if the object itself exists can you attempt to access
a value.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP- FrontPage
"Arpan" <ar******@hotma il.comwrote in message
news:11******** **************@ d34g2000cwd.goo glegroups.com.. .
An ASPX page has the following code:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (IsNothing(Requ est.Cookies("Au thCookie"))) Then
Response.Write( Request.Cookies ("AuthCookie"). Value)
Else
Response.Write( Cookie 'AuthCookie' Doesn't Exist!)
End If
End Sub
Assume that the cookie named "AuthCookie " doesn't exist. As expected,
the Response.Write line in the Else condition gets rendered but if I
change the If condition to
If Not (IsNothing(Requ est.Cookies("Au thCookie").Valu e)) Then
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
Why? Is it because Request.Cookies ("AuthCookie"). Value evaluates to an
expression?
Thanks,
Arpan
c#
== null
"Arpan" <ar******@hotma il.comschreef in bericht
news:11******** **************@ e3g2000cwe.goog legroups.com...
Thanks, Mark....your explanation has indeed been very very helpful.
One more question please - to test the existence of an object, I can
use "IsNothing" (as I did in post #1) & also "Is Nothing" like
If (Request.Cookie s("AuthCookie ") Is Nothing) Then
What I would like to know is are there any performance benefits of one
over the other? Or any other differences between "IsNothing" & "Is
Nothing"? Which among the 2 is more recommended?
Thanks once again,
Regards,
Arpan
Mark Fitzpatrick wrote:
>This throws an error because you can't access a property of an object that doesn't exist. Value is a property, but since the object itself doesn't exist there cannot be any property for it. You always have to test to see if the object exists first, which is what you are doing initially, and only after you test to see if the object itself exists can you attempt to access a value.
Hope this helps, Mark Fitzpatrick Microsoft MVP- FrontPage
"Arpan" <ar******@hotma il.comwrote in message news:11******* *************** @d34g2000cwd.go oglegroups.com. ..
An ASPX page has the following code:
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (IsNothing(Requ est.Cookies("Au thCookie"))) Then
Response.Write( Request.Cookies ("AuthCookie"). Value)
Else
Response.Write( Cookie 'AuthCookie' Doesn't Exist!)
End If
End Sub
Assume that the cookie named "AuthCookie " doesn't exist. As expected,
the Response.Write line in the Else condition gets rendered but if I
change the If condition to
If Not (IsNothing(Requ est.Cookies("Au thCookie").Valu e)) Then
then ASP.NET generates the following error:
Object reference not set to an instance of an object.
Why? Is it because Request.Cookies ("AuthCookie"). Value evaluates to an
expression?
Thanks,
Arpan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Drew |
last post by:
I have been trying to figure out why I am getting this message... I have an
application that is 20 different ASP pages that works in sequential order
(step1, step2, step3...). After each step the app writes the entered text
to a cookie. This feature is so that if there is a problem, we can still
retrieve the data.
This Bad Request error has something to do with the cookie that is written
to, because I can go all the way through the app...
|
by: Bhupesh Saini |
last post by:
I am trying to call a ASPX page using HttpWebRequest class and pass cookie information to it. My ASPX pages gets called just fine, however none of the request cookies are available to the ASPX page. What do I need to do to have the cookies sent along with the request
Below is the code snippet from the function I an using I am using to achieve the above. EVerything works except that I do not see any cookies in request object for the ASPX page...
|
by: CDARS |
last post by:
Hi all,
I have a confusing question on ASP.NET cookies usage:
1> Response.Cookies("test").value = Now
2> Response.Write(Request.Cookies("test").value)
3>
4> Response.write("<hr>")
5>
6> Response.Cookies("test").value = Now.AddDays(10)
|
by: Alex Nitulescu |
last post by:
I have the following very simple colde (while learning about cookies and
session state):
Private Sub cmdAddCookie_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddCookie.Click
Dim strCookieName As String
Dim objRandom As New Random()
strCookieName = "MyCookie" & objRandom.Next(Integer.MaxValue).ToString
|
by: Shawn Berg |
last post by:
Some of my pages in the app I am developing inherit from a BasePage class I
have created. I have done plenty of these in the past and they work fine.
Now, however, I have an additional requirement.
In my BasePage class I need to check the user's browser for a particular
cookie, and if certain conditions aren't met, redirect the user to another
page. You can see the code for my BasePage class below. The problem lies in
the LoggedIn...
| |
by: Miljana |
last post by:
Hi,
I have one problem with cookies in ASP.NET application.
It seems that I can not retreive cookie from Request.Cookies collection.
I put cookie in Response.Cookies collection, and after page post back, when
I try to retreive it from Request.Cookies collection, it appears that it does
not exists.
This problem does not occur on several developing machines we use for
developing application, but occurs in another environment (another...
|
by: user |
last post by:
Hi everyone,
May I know the standard way of reading in cookies in ASP.net using
VB.net?
In classic asp, i can do this:
If request.cookies("user") = "abc" then
blah blah
|
by: dihola |
last post by:
Hi,
I have a website running in IIS7 and it seems to be creating a new session for every request I make. The values I store in Session are lost with every request.
This is the forms bit in my web.config:
<authentication mode="Forms">
<forms name=".ReMaCRM" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" cookieless="AutoDetect" domain="" timeout="10" protection="All" />
</authentication>
|
by: =?Utf-8?B?d2FsdGVy?= |
last post by:
Hi there... we have a list of internal websites. For logging purpose, we
would like to attach some client side info in each HTTP request before submit
to server.
Two options for us : 1) each website can add some script to do so, but the
changes are enumerous; 2) it will be nice if we can inject the info on IE
before it submit the request back to the server.
I personally think option 2 is NOT possible because it posts secuirty issue.
I...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |