![]() |
|
|
|||||||
![]() |
ASP Net - Cookie and FormsAuthenticationTicket Question... |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 Kiran B. |
|
|
|
|
#2 |
|
Posts: n/a
|
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." <> wrote in message news:%... > 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 > > Curt_C [MVP] |
|
|
|
#3 |
|
Posts: n/a
|
Thanks, i forgot to mention, we authenticate user with active directory
using form. Thanks "Kiran B." <> wrote in message news:%... > 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 > > Kiran B. |
|
|
|
#4 |
|
Posts: n/a
|
"Kiran B." <> wrote in message
news:%... > 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 John Saunders |
|
|
|
#5 |
|
Posts: n/a
|
tHANKS JOHN, WOULD EXPLAIN IT IN DETAIL?
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message news:%... > "Kiran B." <> wrote in message > news:%... >> 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 > > Kiran B. |
|
|
|
#6 |
|
Posts: n/a
|
"Kiran B." <> wrote in message
news:%... > tHANKS JOHN, WOULD EXPLAIN IT IN DETAIL? Answer inline: > "John Saunders" <johnwsaundersiii at hotmail.com> wrote in message > news:%... >> "Kiran B." <> wrote in message >> news:%... >>> 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 John Saunders |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ASP.Net Session Cookie Lost on mozilla/netscape After return from cross domain | saurabhm | Software | 3 | 09-18-2009 12:36 PM |
| Kill Bill Subtitle Question | Tony soprano | DVD Video | 4 | 04-21-2004 01:25 PM |
| DVD burning speed question | Steve84 | DVD Video | 3 | 09-22-2003 08:48 PM |