473,486 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

forms authentication question

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:

strUserName = CType(drOLEDBNicemScheduling.GetValue(1) &
Chr(32) & drOLEDBNicemScheduling.GetValue(2), String)
'Set the authentication ticket
Dim arrRoles(0) As String
arrRoles(0) =
drOLEDBNicemScheduling.GetValue(3)
Dim ticket As New
FormsAuthenticationTicket(1, strUserName, Now, DateAdd
(DateInterval.Minute, 60, Now),
ValidateLogin.PersistantCookie, arrRoles(0))
Dim cookie = New HttpCookie
(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(ticket))
If ValidateLogin.PersistantCookie Then
Response.Cookies.Add(cookie)
End If
'Create Identity
Dim objIdentity As New
Security.Principal.GenericIdentity(strUserName)
Dim objPrincipal As New
Security.Principal.GenericPrincipal(objIdentity, arrRoles)

FormsAuthentication.RedirectFromLoginPage(strUserN ame,
ValidateLogin.PersistantCookie)

However, once I get in the Global.asax file in
the "Application_AuthenticateRequest" event (fired by the
FormsAuthentication.RedirectFromLoginPage method), I check
the "UserData" property of the ticket and it's an empty
string! All the other properties pertaining to the ticket
are there. I'm setting up the cookie, so the "Userdata"
property should be populated.

Here is the code in the global.asax file:

Sub Application_AuthenticateRequest(ByVal sender As
Object, ByVal e As EventArgs)

If (Not (HttpContext.Current.User Is Nothing)) Then
If
HttpContext.Current.User.Identity.AuthenticationTy pe
= "Forms" Then
If
HttpContext.Current.User.Identity.IsAuthenticated Then
Dim id As FormsIdentity =
HttpContext.Current.User.Identity
Dim ticket As
FormsAuthenticationTicket = id.Ticket
Dim roles(0) As String
roles(0) = ticket.UserData
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(id, roles)
End If
End If
End If

End Sub

What am I doing wrong??? I need to be able to identify the
role of the user (they will only have 1 role).

Thanks,

Bill........
Nov 17 '05 #1
0 2247

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

Similar topics

6
4790
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
3
2689
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
11
3531
by: ElmoWatson | last post by:
I tried on the Security newgroup, as well as other places, and haven't gotten an answer yet - - I'm pulling my hair out over this one. I'm trying to get Forms Authentication working.....I can get...
1
3474
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
2
2481
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having...
7
2020
by: Justin | last post by:
I am trying to password protect a subdirectory using forms authentication. I am using the "Location" tag to specify the directory to be protected. The login.aspx page is in the root directory of...
5
1652
by: V. Jenks | last post by:
Using forms authentication, can I control which pages and/or directories a user would have access to or is that only available with Windows authentication? Thanks!
18
6850
by: Rippo | last post by:
Hi I am using role base forms authentication in asp.net and have come across a problem that I would like advice on. On a successful login a session variable is set to identify a user. This is...
4
5312
by: Bjorn Sagbakken | last post by:
In a web-application with login creds (user, pwd), these are checked against a user table on a SQL server. On a positive validation I have saved the userID, name, custno and role-settings in a...
5
3525
by: Rory Becker | last post by:
Having now created a Custom MembershipProvider that seems to work correctly with my Logon and ChangePassword controls, I am, as they say, a happy bunny. The next stange is to move on to the...
0
7094
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
7123
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,...
1
6839
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
7305
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
5427
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,...
1
4863
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...
0
4559
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...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
259
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...

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.