473,437 Members | 1,732 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,437 software developers and data experts.

Cookie and FormsAuthenticationTicket Question...

New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and 201
in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.

Thanks
Nov 19 '05 #1
5 1916
Just put it in a Session object item
(C# version)

Write:
Session["SalesID"] = "201";

Read:
string SalesID = Session["SalesID"].ToString();
--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and 201
in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.

Thanks

Nov 19 '05 #2
Thanks, i forgot to mention, we authenticate user with active directory
using form.

Thanks
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and 201
in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.

Thanks

Nov 19 '05 #3
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and 201
in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.


Assuming that "groups" is the user data for the ticket, I'd put the sales id
in there as well. In your global.asax, when you're interpreting the user
data, you would extract the sales id from the ticket.

Now, you want to put it in Session, and I suppose you could do that.
Personally, I wind up defining a new class implementing IPrincipal and
adding a SalesId property. That way, the SalesId can be accessed from
anywhere, and can even be passed to components which don't know about
Session state.

John Saunders
Nov 19 '05 #4
tHANKS JOHN, WOULD EXPLAIN IT IN DETAIL?
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and
201 in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.


Assuming that "groups" is the user data for the ticket, I'd put the sales
id in there as well. In your global.asax, when you're interpreting the
user data, you would extract the sales id from the ticket.

Now, you want to put it in Session, and I suppose you could do that.
Personally, I wind up defining a new class implementing IPrincipal and
adding a SalesId property. That way, the SalesId can be accessed from
anywhere, and can even be passed to components which don't know about
Session state.

John Saunders

Nov 19 '05 #5
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
tHANKS JOHN, WOULD EXPLAIN IT IN DETAIL?
Answer inline:
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Kiran B." <kb********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
New to .net... I am wondering if I have a user name as userone and this
userone has sepcial sales id 201, how can i associate both userone and
201 in a cookie and access it later on. I can access user name using...

Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

It works fine. Now I need a way to associate sales id as they log in and
should be accessible through out their session.


Assuming that "groups" is the user data for the ticket, I'd put the sales
id in there as well. In your global.asax, when you're interpreting the
user data, you would extract the sales id from the ticket.
Dim salesId As Integer ' = Whatever
Dim userData As String = salesId.ToString() & "|" & groups
Dim authTicket As FormsAuthenticationTicket = New
FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddMinutes(60), isCookiePersistent, userData )
Now, you want to put it in Session, and I suppose you could do that.
Personally, I wind up defining a new class implementing IPrincipal and
adding a SalesId property. That way, the SalesId can be accessed from
anywhere, and can even be passed to components which don't know about
Session state.


Public Class MyPrincipal
Inherits System.Security.Principal.GenericPrincipal

Private _salesID As Integer

Public Sub New(ByVal identity As System.Security.Principal.IIdentity,
ByVal roles As String(), ByVal salesID As Integer)
MyBase.New(identity, roles)
_salesID = salesID
End Sub

Public ReadOnly Property SalesId() As Integer
Get
Return _salesID
End Get
End Property
End Class
Then, in Application_AuthenticateRequest in Global.asax.vb, after you
decrypt the Forms Authentication Ticket:

Dim userData As String = ticket.UserData
Dim userDataFields As String() = userData.Split("|"c)
Dim salesId As Integer = Integer.Parse(userDataFields(0))
Dim roles As String() = userDataField(1).Split(","c)
'
Dim principal As New MyPrincipal(Request.User.Identity, roles, salesId)
Request.User= principal

Then, on every authenticated page, you can use:

Dim principal As MyPrincipal = DirectCast(User, MyPrincipal)
' you can now access principal.SalesID

I hope that helps,
John Saunders
Nov 19 '05 #6

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

Similar topics

2
by: George Durzi | last post by:
When you call FormsAuthentication.SignOut(), is the FormsAuthentication cookie supposed to be destroyed automatically? I'm creating my FormsAuthentication cookie by doing: HttpCookie oCookie =...
0
by: Kepler | last post by:
I'm testing very basic FormsAuthentication and having trouble with non-persistent cookies. Once authenticated with a non-persistent cookie, if I leave the browser alone for 30 minutes,...
1
by: WJ | last post by:
Cookie Bakers ! 1. I cannot find my cookies in my client XP folder (C:\Documents and Settings\MyWindowsLoginID\Cookies). I tried to find it while I am still in the browser and while I log out...
0
by: Benny Ng | last post by:
The method of following can generated the cookie for login: //isPersistent is true; FormsAuthentication.SetAuthCookie(Session.ToString() ,isPersistent) ;
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,...
8
by: bashful.belle | last post by:
I'm using Forms authentication and a non persistent cookie in my asp.net application. How do i get the cookie to time out after a period of inactivity, say 10 minutes, and force the user to login...
15
by: Edwin Knoppert | last post by:
I have searched but info is limitted. In my test app i used a non persistant cookie for forms authentication. slidingExpiration is set to true On run and close and rerun the login remains ok....
5
by: SJ | last post by:
Hi, In my website, i have a cookie that allows the user to remain logged in for upto 90days. So I'm setting the cookie expiration time to 90 days in the future from the time the user logs in....
3
by: rh.krish | last post by:
I have a typical ASP.NET 2.0 Forms authentication application which authenticates against Active Directory. I use non-persistent cookie so that the user is NOT remembered across browser sessions....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.