473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

create cookie with keys using GetAuthCookie

This is how I am using the GetAuthCookie using the FormsAuthentication
object:

'after successful login
Dim hCookie As HttpCookie

FormsAuthentication.RedirectFromLoginPage(txtUserN ame.Text, True)
hCookie = FormsAuthentication.GetAuthCookie(txtUserName.Text , True)
hCookie.Name = "UserName"
hCookie.Value = txtUserName.Text
hCookie.Expires = DateTime.Now.AddMonths(2)
Response.Cookies.Add(hCookie)

The above creates a HttpCookie with the encrypted ticket information
along with the username. Now how do I add a key named, say, UID to this
cookie which will store the UserID of the logged-in user (which will be
retrieved from a SQL Server 2005 DB table) so that next time whenever
the user comes to this page, I can display a message saying that his
UserID is, say, 4 (or whatever it is corresponding to the logged-in
user)?

Also note that I have set the cookie to expire after 2 months. Suppose
a user logs in successfully after which he is shown a hello message
with his username. Next he closes the browser window in which he logged
himself & opens a new browser window. This page still displays him the
hello message with his username (i.e. the user isn't forced to login
again just because he has opened a new browser window).

Everything fine till this point but suppose the user comes to this page
the next day (or after a few days but within 2 months before his last
login), ASP.NET again asks the user to login though the cookie has been
set to expire after 2 months. Why so?

How do I ensure that the user is not forced to login for the next 2
months (or whatever expiry period has been set for the cookie to
expire) once he logs in?

Oct 1 '06 #1
0 1508

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried...
1
by: Vikram Bhatia | last post by:
In my web application we are able to store large data in the browser cookie keeping in mind the limit of 300 cookies per cookie file, 20 keys per cookie per domain and 4KB max size of each cookie....
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
1
by: Chad Richardson | last post by:
I have several users data elements that I want to maintain and persist. I've created a cookie with keys to do this, but having problems with it persisting. 1. Do you set the .Expires at the...
3
by: James | last post by:
Have a look at the following ASP code; <%Response.Buffer=true%> <HTML> <BODY> <% Dim itema Dim itemqa
8
by: Bill Henning | last post by:
Another developer and I have noticed that after upgrading to the ASP.NET 2.0 RTM release, when using: FormsAuthentication.SetAuthCookie(userName, true) That the cookie is no longer persisted,...
2
by: Niko | last post by:
Hi I have a big problem with some browser setting wrong ASP.NETSessionid in a cookie, and the result is that asp.net 1.1 always assigns new session to the client. I checked what is going on and...
7
by: =?Utf-8?B?SlA=?= | last post by:
I need to design a WS that will after authenicating the user, create a cookie on the users PC that made the request. All the code I keep finding is how to get a WS to read a cookie, I need it to...
5
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.