Solved

Set Cookie in ASP.NET

Posted on 2007-11-14
4
1,770 Views
Last Modified: 2012-08-14
Hi Experts

I am trying to set a cookie in ASP.NET

What I want to do is store the Id of the logged in user into a cookie.

What I have is

Response.Cookies("LoggedInUser").Expires = "5/1/2010"
Response.Cookies("LoggedInUser").Value = Request.Form("emailAddress")

And it works fine

But I want to store the Id not the email address. From My stored procedure I get the login information
The Id output is

<%# Get_Login.FieldValue("Id", Container) %>

How do I merge the two?

Cheers
0
Comment
Question by:nikdonovanau
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:cmhunty
ID: 20279158
What's Get_Login?

You'd just create a method which returns the ID from the stored proc and set Response.Cookies("LoggedInUser").Value to the value it returns.
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 20279188
Yes, Thats exactly what I am after.

What is the correct Syntax to do that.

The Get_Login is the name of my stored procedure.

Sorry if the question seems basic. I am a php devloper and a client of ours needs this proj in vb.net
Its only my second day learning vb.net.

I thought something like
Response.Cookies("LoggedInUser").Value = Get_Login.FieldValue("Id", Container)

But that doesnt do it.
Cheers
0
 
LVL 11

Accepted Solution

by:
cmhunty earned 500 total points
ID: 20279231
If you've got the stored proc called Get_Login, create a method called GetLogin or something like that which returns at integer - something like this.......

    Private Function GetLogin() As Integer
        Dim strConn As String = "connection string"
        Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
        Dim cmd As New System.Data.SqlClient.SqlCommand("Get_Login")
        cmd.CommandType = Data.CommandType.StoredProcedure
        Dim intLogin As Integer = -1
        conn.Open()
        intLogin = cmd.ExecuteScalar
        conn.Close()
        Return intLogin
    End Function

Then set the cookie using

Response.Cookies("LoggedInUser").Value = GetLogin
0
 
LVL 1

Author Comment

by:nikdonovanau
ID: 20279303
Thanks mate.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now