Solved

Set Cookie in ASP.NET

Posted on 2007-11-14
4
1,773 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

822 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