AuthenticateRequest event and Roles

G

Guest

I'm using code similar to below. Is there a way to check if the Current.User
object has roles assigned already. This event fires on every page request and
I only need to have it fired once since it makes a call to the db everytime.
Thanks.

Sub Application_AuthenticateRequest(sender As Object, e As EventArgs)
If Request.IsAuthenticated Then
'Determine this user's roles
Dim reader As SqlDataReader = _
SqlHelper.ExecuteReader(connection string, _
CommandType.StoredProcedure, "rolesForUser", _
New SqlParameter("@Username", User.Identity.Name))

' Create an array of role names
Dim roleList As New ArrayList
Do While reader.Read()
roleList.Add(reader("Name"))
Loop

'Convert the roleList ArrayList to a String array
Dim roleListArray As String() = roleList.ToArray(GetType(String))

'Add the roles to the User Principal
HttpContext.Current.User = _
New GenericPrincipal(User.Identity, roleListArray)
End If
End Sub
 
D

Daniel TIZON

Hy Dave,
You could save the roles in a cookie, if you don't have too much roles to
save, but you should encrypt it...
Another solution would be to use the Session, but I think it isn't available
at this time in the Application_AuthenticateRequest

I know that in ASP.NET2.0 all the code is already written to read/write the
roles in a DB... and to optimize the role list access in a cookie if you
need it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top