Solved

Set Cookie in ASP.NET

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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