Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
dear all
i am using cokees like this and then it works fine this is login page and redirect on other page works fine

VB
Dim cokee As HttpCookie
               cokee = New HttpCookie("userinfo")
               'cokee.Expires = DateTime.Now.AddDays(30)
               cokee("name") = "Welcome:" & vbTab & reader("fname") & vbTab & reader("lname")
               Response.Cookies.Add(cokee)
               Response.Redirect("jobdetail.aspx")

second page code to read cokees
VB
Dim cokee As HttpCookie = Request.Cookies("userinfo")
       lblogin.Text = cokee("name")



but problem when i closed broswr and past old link as i copy
http://localhost:1034/job%20online/jobdetail.aspx[^]
when i past this browser give this error
XML
Server Error in '/job online' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:
Posted
Comments
[no name] 29-Apr-14 19:19pm    
And your problem or question is what? Did you read the error message? Did you do anything that the error message gave you explicit instructions to do? Did you debug your code? Did you find the object that was null that you was trying to use?
RahulMGunjal 29-Apr-14 23:59pm    
debug the code line by line and find the code giving the error

1 solution

You should first check if cookie exists or not.
VB
If Not Request.Cookies("userinfo") Is Nothing Then
    'Code if cookie does not exist
    Dim cokee As HttpCookie = Request.Cookies("userinfo")
    lblogin.Text = cokee("name")
End If
 
Share this answer
 
v2
Comments
Sanket Saxena 30-Apr-14 0:39am    
Exactly just need to check the cookie first. Obviously it is not exist that's why the error of object reference. +5
Thanks a lot Sanket. :)
irfanansari 30-Apr-14 0:53am    
i wrote this code
If Not Request.Cookies("userinfo") Is Nothing Then
'Code if cookie does not exist
lblogin.Text = "no cokee"
Else

Dim cokee As HttpCookie = Request.Cookies("userinfo")
lblogin.Text = cokee("name")
End If

this is shows msg no cokeeks
but when i was working it was working fine and when i closed broswer then that error comes
Debug your code and see if it is going inside the If block or not when you move from a Page to this page that is after creating the Cookie.

And yes, when you close the browser, Cookie is lost, so it was throwing exception. That's why I suggested you to check if it exists or not before reading its value.
irfanansari 30-Apr-14 3:30am    
i try to debug then this erorr come

Server Error in '/job online' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true">



Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900