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

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 CreateCredentials code:

Private Sub CreateCredentials(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.Security.FormsAuthenticationTicket
Dim AuthIdentity As System.Web.Security.FormsIdentity
Dim MinutesUntilExpiration As Double

CurrentContext = HttpContext.Current
' The session timeout limit is defined in the web.config file
MinutesUntilExpiration =
CType(ConfigurationSettings.AppSettings("WLTTimeOu tMinutes"), Double)
Ticket = New System.Web.Security.FormsAuthenticationTicket(1,
UserID, DateTime.Now, _

DateTime.Now.AddMinutes(MinutesUntilExpiration), _
False,
UserRole)

' Add ticket into user's cookie list and put the ticket into the
user's HTTP Context
FormsCookie = System.Web.Security.FormsAuthentication.Encrypt(Ti cket)
AuthCookie = New
HttpCookie(System.Web.Security.FormsAuthentication .FormsCookieName,
FormsCookie)
CurrentContext.Response.Cookies.Add(AuthCookie)

End Sub

Similarly, in my global.asax I have the following

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

Dim id As System.Web.Security.FormsIdentity
Dim ticket As System.Web.Security.FormsAuthenticationTicket

' Update authentication ticket greated during login to include
the user's role in its credentials.
If Not HttpContext.Current.User Is Nothing Then
If HttpContext.Current.User.Identity.IsAuthenticated Then
If TypeOf HttpContext.Current.User.Identity Is
System.Web.Security.FormsIdentity Then
id = CType(HttpContext.Current.User.Identity,
System.Web.Security.FormsIdentity)
ticket = id.Ticket
Dim UserRole() As String = {""}
UserRole(0) = ticket.UserData
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(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_authentication, but the
UserData doesn't go with it. Here is my debug info:

Login Form:
?Ticket
{System.Web.Security.FormsAuthenticationTicket}
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.Security.FormsAuthenticationTicket}
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 1494

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

Similar topics

0
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...
11
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"}...
1
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...
0
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...
3
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...
4
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...
0
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...
3
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...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
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,...

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.