Problem with accessing cookies?

L

lalitha1024

Hi,
In my Asp.net project when i am login to my site, i'll set th
cookies by using below commands.

Dim IdCookie As New HttpCookie("empid"
ds.Tables(0).Rows(0).Item(0))
Dim FnameCookie As New HttpCookie("empname"
ds.Tables(0).Rows(0).Item(1))
Response.Cookies.Add(IdCookie)
Response.Cookies.Add(FnameCookie)

In each and every page i wrote authorization by using belo
statements.

If Request.Cookies("empid").Value = "" Then
Response.Write("<b> You are not authorised to view thi
page...</b>")
Server.Transfer("employerlogin.aspx")
End If

when i am trying to execute pages separetely in browser i am gettin
below error. i am copying here my total error page.

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

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

Source Error:


Line 24: Private Sub Page_Load(ByVal sender As System.Object, ByVa
e As System.EventArgs) Handles MyBase.Load
Line 25: Dim id As String
Line 26: id = Request.Cookies("empid").Value
Line 27: 'If CType(Response.Cookies("empid").Value, String)
"" Then
Line 28:


Source File: c:\inetpub\wwwroot\Gotsap\emphome.aspx.vb Line: 26

Stack Trace:


[NullReferenceException: Object reference not set to an instance of a
object.]
Gotsap.emphome.Page_Load(Object sender, EventArgs e) i
c:\inetpub\wwwroot\Gotsap\emphome.aspx.vb:26
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573
ASP.NET Version:1.1.4322.573

What is the error, i am not able to understand.

Plz help me out.

Thanks in advance.

Lalitha.
 
C

Clint Hill

Where are you setting the following:

Dim IdCookie As New HttpCookie("empid",
ds.Tables(0).Rows(0).Item(0))
Dim FnameCookie As New HttpCookie("empname",
ds.Tables(0).Rows(0).Item(1))
Response.Cookies.Add(IdCookie)
Response.Cookies.Add(FnameCookie)

Is this in Page_Load or is it in Global? It seems on the face of it
you're trying to use a Cookie that doesn't exist. Hence the
NullReference exception. If you could share emphome.aspx.cs that would
be helpful as well.

Clint Hill
H3O Software
http://www.h3osoftware.com
 
L

lalitha1024

Hi,
i am new to asp.net. i am setting cookies in the login page, afte
successful login means in the submit button click.
any other way to set cookies and plz help to solve my problem.
i am very sorry to say like that, i am not able to understand belo
words
"If you could share emphome.aspx.cs that would be helpful as well"
can you plz explain detaild.

thanking you,

Lalitha.
 
C

Clint Hill

I was asking you to share the code that sets the cookie. It is likely in
the emphome.aspx.vb file (codebehind). That is where the stack trace
showed the exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

problem with cookies and graphics 0
Cookies 1
Cookies 1
Using Cookies 0
Clearing cookies 2
Cookies during error handling 1
What is the proper way to use cookies? 1
Functioning website now fails 0

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top