Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET: Using a Cookie

Posted on 2003-12-06
7
Medium Priority
?
628 Views
Last Modified: 2011-09-20
I have an internal login page where I need to be able to use a Cookie (or something) else to Save the user name and password when the user chenck a textbox then logs in.

   Thanks!

     - Marc
0
Comment
Question by:MarcGraff
[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
7 Comments
 
LVL 5

Accepted Solution

by:
arjanh earned 2000 total points
ID: 9888815
Here is a good example of using cookies in ASP.NET:
http://www.stlvbug.org/aspnet/cookie.aspx
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 9889008
here is the complete sample of what you ask
http://www.gotdotnet.com/team/student/wintellect/aspnet_tutorial.aspx

B..G
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 9889295
Hi,

I'm not working with cookies anymore! -> I work "cookieless" ;-))

I save the Session GUID to the database -> as long as the user stays in that session I can track anything happening -> the rest (information management) is done by "user" classes -> one for logon another one for having access to user profile and so on ...

After accessing the website the user sees the following (as an example!) http://www.w62.net/(knmqwfv3smmyruajhg2juc2b)/Default.aspx

Everything is kept in the database with that key "knmqwfv3smmyruajhg2juc2b" -> and some more security features ;-))


... are you interested in that technology or are you going to accept the link above?


Best regards, Raisor
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Author Comment

by:MarcGraff
ID: 9889473
Raisor:
I love your pitch on "cookieless"...

How does the database get information back after the user logs off and logs on the next day?

   - Marc
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9889479
BTW Sorry about the time delay but I am still trying to get it all to work.

   - Marc
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 9889762
Hi,

Here we go:

-> the user comes as visitor to the site
-> the visitor is attached to a session GUID
-> if visitor logs on successfully the visitor is attached to the user ID
-> if user doesn't log on the visitor remains attached to session GUID
-> if visitor returns any other time the user is attached to a new session GUID
-> if visitor logs on successfully after any other return the user is attached to the user ID

What is this good for? ->

Many users have cookies disabled ... I have statistics from many sites of mine about this issue!
So any specific user information that is necessary to process your web sites critical business processes will be blown to air if you only depend on cookies and cookies are disabled!

I used to send visitors without cookies enabled to http://www.visitors-without-enabled-cookies.com trying to convince them there to enable cookies -> I tell you … that didn’t work at all and in the meantime I dropped that domain!

Here is one part of code from a Page_Load event that documents a basic how-to (and show which information I pick from unknown visitors!) …

            If Page.IsPostBack = False Then
                  If Not Request.ServerVariables("HTTP_ASPFILTERSESSIONID") Is Nothing Then
                        myGuestID = Request.ServerVariables("HTTP_ASPFILTERSESSIONID").ToString
                        Dim [myDB] As New snifferDB()
                        If [myDB].CheckVisitorCount(myGuestID) = 0 Then
                              If Not Request.ServerVariables("REMOTE_ADDR") Is Nothing Then
                                    myVisitorIP = Request.ServerVariables("REMOTE_ADDR").ToString
                              Else
                                    myVisitorIP = "0.0.0.0"
                              End If
                              If Not Request.ServerVariables("HTTP_REFERER") Is Nothing Then
                                    myVisitorREF = Request.ServerVariables("HTTP_REFERER").ToString
                              Else
                                    myVisitorREF = "From Heaven"
                              End If
                              myVisitorDLang = 0
                              Dim [myTime] As New TimeFunction()
                              myVisitorTime = [myTime].Generate_Timestamp(Day(Now), Month(Now), Year(Now), Hour(Now), Minute(Now), Second(Now))
                              [myTime] = Nothing
                              myVisitorSession = myGuestID
                              Dim myInterestBuffer As New webactBuffer()
                              myInterestBuffer.theIP = myVisitorIP
                              myInterestBuffer.theRef = myVisitorREF
                              myInterestBuffer.theDLang = myVisitorDLang
                              myInterestBuffer.theSLang = myVisitorSLang
                              myInterestBuffer.theSDialect = myVisitorSDialect
                              myInterestBuffer.theTime = myVisitorTime
                              myInterestBuffer.theSession = myVisitorSession
                              Dim myInterest As Boolean = myDB.AddActData(1, myInterestBuffer)
                              myInterestBuffer = Nothing
                              myInterest = Nothing
                        End If
                        [myDB] = Nothing
                  End If
            End If
      End Sub



This all relies on HTTP_ASPFILTERSESSIONID and this is the setting in "web.config" to retrieve cookieless state:

    <sessionState
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;user id=sa;password="
            cookieless="true"
            timeout="20"
    />


Please take this piece of code only as is … if you’re further interested I’ll prepare some more for you!


Best regards, Raisor
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9890077
I love this method even though I don't completly understand it. I would love to learn more about it so I created another question:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20818484.html

I will have to use cookies while I learn "The Raisor" method but look forward to implementing "The Raisor" method in my next ASP page!

   - Marc
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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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