473,790 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Authentication Ticket not storing UserData

Hey all,

I've followed the examples online on how to use Forms Authentication to
create a ticket, assign it a role, and then intercept it in the
Global.asax file to make sure it gets sucked in to the IPrincipal. This
has worked on some other apps, but my code isn't working in my new one
for some reason. Here's my CreateCredentia ls code:

Private Sub CreateCredentia ls(ByVal UserID As String, ByVal UserRole As
String)

Dim CurrentContext As HttpContext
Dim FormsCookie As String
Dim AuthCookie As HttpCookie
Dim Ticket As System.Web.Secu rity.FormsAuthe nticationTicket
Dim AuthIdentity As System.Web.Secu rity.FormsIdent ity
Dim MinutesUntilExp iration As Double

CurrentContext = HttpContext.Cur rent
' The session timeout limit is defined in the web.config file
MinutesUntilExp iration =
CType(Configura tionSettings.Ap pSettings("WLTT imeOutMinutes") , Double)
Ticket = New System.Web.Secu rity.FormsAuthe nticationTicket (1,
UserID, DateTime.Now, _

DateTime.Now.Ad dMinutes(Minute sUntilExpiratio n), _
False,
UserRole)

' Add ticket into user's cookie list and put the ticket into the
user's HTTP Context
FormsCookie = System.Web.Secu rity.FormsAuthe ntication.Encry pt(Ticket)
AuthCookie = New
HttpCookie(Syst em.Web.Security .FormsAuthentic ation.FormsCook ieName,
FormsCookie)
CurrentContext. Response.Cookie s.Add(AuthCooki e)

End Sub

Similarly, in my global.asax I have the following

Sub Application_Aut henticateReques t(ByVal sender As Object, ByVal e As
EventArgs)
' Fires upon attempting to authenticate the user

Dim id As System.Web.Secu rity.FormsIdent ity
Dim ticket As System.Web.Secu rity.FormsAuthe nticationTicket

' Update authentication ticket greated during login to include
the user's role in its credentials.
If Not HttpContext.Cur rent.User Is Nothing Then
If HttpContext.Cur rent.User.Ident ity.IsAuthentic ated Then
If TypeOf HttpContext.Cur rent.User.Ident ity Is
System.Web.Secu rity.FormsIdent ity Then
id = CType(HttpConte xt.Current.User .Identity,
System.Web.Secu rity.FormsIdent ity)
ticket = id.Ticket
Dim UserRole() As String = {""}
UserRole(0) = ticket.UserData
HttpContext.Cur rent.User = New
System.Security .Principal.Gene ricPrincipal(id , UserRole)
End If
End If
End If

End Sub

For some reason, when I debug, I trace the script through the create
credentials striaght into the application_aut hentication, but the
UserData doesn't go with it. Here is my debug info:

Login Form:
?Ticket
{System.Web.Sec urity.FormsAuth enticationTicke t}
CookiePath: "/"
Expiration: #1/24/2005 4:12:16 PM#
Expired: False
IsPersistent: False
IssueDate: #1/24/2005 3:52:16 PM#
Name: "spatterson "
UserData: "USER"
Version: 1

Global.asax
{System.Web.Sec urity.FormsAuth enticationTicke t}
CookiePath: "/"
Expiration: #1/24/2005 4:22:32 PM#
Expired: False
IsPersistent: False
IssueDate: #1/24/2005 3:52:32 PM#
Name: "spatterson "
UserData: ""
Version: 1

Any help to what I'm missing? I've even cleared out my cookies in IE to
test things. Thanks in advance!
Nov 19 '05 #1
0 1516

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

Similar topics

0
2265
by: bill yeager | last post by:
Everything is working in my authentication process except for the fact that I can't retrieve the "UserData" property from the "FormsAuthenticationTicket". Write before I do a "RedirectFromLoginPage", I check the "UserData" property of the "FormsAuthenticationTicket". It's set to the value "Admin" (a role for the user) which is what I want. Here is the code:
11
1721
by: VB Programmer | last post by:
PLEASE HELP.... I'm having trouble. In my login form after I've verified the username/password are valid I do this: Select Case iMyPrivilege Case 0 Dim arrRoles() As String = {"guest"} Context.User = New System.Security.Principal.GenericPrincipal(User.Identity, arrRoles) Case 1
1
6374
by: e | last post by:
I'm using forms authentication on a site. When the user logs in via the login page, the entered creds are checked against AD, and if valid, an encrypted forms authentication ticket is produced and stored in the forms auth cookie (and written to the client), using this code: ____________________ 'create the forms auth ticket objAuthTicket = New FormsAuthenticationTicket(1, txtUsername.Text, _ DateTime.Now, DateTime.Now.AddMinutes(8),...
0
1240
by: francois | last post by:
hello, I am using forms authentication and I would like that my authentication cookie expires after let say 1 minutes (just for the exemple). When I log in in my longon page, the user has to input a username, password and the click a button to effectively login. In the event handler for my button I have the following code: // create authentication ticket and encrypt it
3
4744
by: Martin | last post by:
Dear fellow ASP.NET programmer, I stared using forms authentication and temporarily used a <credentials> tag in web.config. After I got it working I realized this wasn't really practical. I cannot write to web.config so I cannot dynamically update the credentials while the site is up. Since the FormsAuthentication.Authenticate() method's documentations claims the following: "Attempts to validate the credentials against those contained...
4
2595
by: Trevor Andrew | last post by:
Hi There, Hopefully this isn't too difficult a question to express here. I have a 3 tier application. 1. Presentation Tier: ASP.NET web application. 2. Middle Tier: ASP.NET Web Services that invoke COM based API for a third party product. 3. Data Tier: A SQL Server database that I can only access via the API. The user authentication for the web application is actually done via a call
0
1327
by: Sean Patterson | last post by:
Hey all, I've followed the examples online on how to use Forms Authentication to create a ticket, assign it a role, and then intercept it in the Global.asax file to make sure it gets sucked in to the IPrincipal. This has worked on some other apps, but my code isn't working in my new one for some reason. Here's my CreateCredentials code: Private Sub CreateCredentials(ByVal UserID As String, ByVal UserRole As String)
3
2308
by: chuck rudolph | last post by:
Folks, Can anyone confirm that my understading is correct and maybe shed some light on why it's as it is. (I'm guessing security, but that seems weak to me.) The asp.net web application is using forms authentication. If I create an FormsAuthTicket with userdata in the approprite place. Then encode it and create a cookie, add it to the response.cookie collection and use it all is well.
1
7090
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi all, I am running ASP.NET 2.0, after login I need to pass CustomerID in my database instead of username to other pages. I added following code to my login.aspx protected void Login_Authenticate(object sender, AuthenticateEventArgs e) { //FormsAuthentication.SignOut(); if (Membership.ValidateUser(Login.UserName, Login.Password)) { int customerID = GetCustomerIDByUsername(Login.UserName); if (customerID 0) {
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7530
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.