Forms based roles assignment problem
From: Rob Heckart (rheckart@nospam.cssiinc.com)
Date: 09/25/02
- Next message: Polux: "Re: Context.User lifetime"
- Previous message: VSK: "difference between CODE ACCESS SECURITY and Role based security"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Rob Heckart" <rheckart@nospam.cssiinc.com> Date: Wed, 25 Sep 2002 15:32:20 -0400
Hi,
I've got forms based authentication going, but I am trying to assign a role
to a user. Here's the code, pretty much straight from the MS KB article
Q306238:
Imports System.Web.Security
Imports System.Security.Principal
...
' Add the user as an admin if they are one
If .Parameters("@IsAdmin").Value And _
(Not (HttpContext.Current.User Is Nothing)) Then
If aUserRoles.GetUpperBound(0) = -1 Then
ReDim Preserve aUserRoles(aUserRoles.GetUpperBound(0) + 1)
End If
aUserRoles(aUserRoles.GetUpperBound(0)) = "Admin"
If (Not (HttpContext.Current.User Is Nothing)) Then
If HttpContext.Current.User.Identity.AuthenticationType = "Forms"
Then
Dim ID As System.Web.Security.FormsIdentity
ID = HttpContext.Current.User.Identity
HttpContext.Current.User = New
System.Security.Principal.GenericPrincipal(ID, aUserRoles)
End If
End If
End If
In my Web.Config file in the root, I have <authentication mode="Forms"> set.
When I run the code, the
HttpContext.Current.User.Identity.AuthenticationType returns blank. When I
comment out that line, the ID = HttpContext.Current.User.Identity comes
back with a cast error.
How is the AuthenticationType set up for the web app so that this works? Do
I need to set something special up in global.asax, web.config or the home
page?
Thanks,
Rob Heckart
- Next message: Polux: "Re: Context.User lifetime"
- Previous message: VSK: "difference between CODE ACCESS SECURITY and Role based security"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|