Solved

Set Cookie in ASP.NET

Posted on 2007-11-14
4
1,776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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