Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Cookie and FormsAuthenticationTicket Question...

 
Thread Tools Search this Thread
Old 12-30-2004, 05:17 PM   #1
Default 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




Kiran B.
  Reply With Quote
Old 12-30-2004, 05:23 PM   #2
Curt_C [MVP]
 
Posts: n/a
Default Re: Cookie and FormsAuthenticationTicket Question...
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]
  Reply With Quote
Old 12-30-2004, 05:41 PM   #3
Kiran B.
 
Posts: n/a
Default Re: Cookie and FormsAuthenticationTicket Question...
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.
  Reply With Quote
Old 12-30-2004, 08:01 PM   #4
John Saunders
 
Posts: n/a
Default Re: Cookie and FormsAuthenticationTicket Question...
"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
  Reply With Quote
Old 01-04-2005, 12:54 AM   #5
Kiran B.
 
Posts: n/a
Default Re: Cookie and FormsAuthenticationTicket Question...
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.
  Reply With Quote
Old 01-04-2005, 04:38 PM   #6
John Saunders
 
Posts: n/a
Default Re: Cookie and FormsAuthenticationTicket Question...
"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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46