Forms based roles assignment problem

From: Rob Heckart (rheckart@nospam.cssiinc.com)
Date: 09/25/02


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



Relevant Pages

  • Re: Single sign-on between web & desktop
    ... web app, starting with something like ASP.NET forms authentication is ... Joe Kaplan-MS MVP Directory Services Programming ... "User credentials come from a Windows domain" should be "User ...
    (microsoft.public.dotnet.security)
  • Re: 401 Access Denied while accessing WSE 3.0 WebService
    ... I also tried impersonating an account ... web app. ... > what kind of authentication you have turned on in IIS? ... > the ASPNET user access to the WS and all dependant resources thereof? ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Web Authentication
    ... If your end users need to access your web app from the internet rather than ... authentication. ... > will have full control rights for a specific windows user. ... I can make the user login with a certian windows username and password then ...
    (microsoft.public.dotnet.security)
  • Re: Newbie Windows Authentication, IIs and Intranet vs Internet users.
    ... require some other kind of authentication instead (eg Basic, Integrated, ... Change your Application Programming Environment to use IIS' ... you can toggle Windows authentication on in your web.config ... > 2) Do user accounts get stored in Db of the new web app? ...
    (microsoft.public.inetserver.iis.security)
  • Re: Authentication problems on IIS6
    ... > I set up a couple applications that set user authentication via an asp ... sometimes after proceeding a few ... > If I link directly to the web app via the sites IP address instead of the ...
    (microsoft.public.inetserver.iis)