FormsAuthentication Roles Problem

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default FormsAuthentication Roles Problem

    I want to use FormsAuthentication and allow access based on role.

    I have a /Admin directory on the web app, and want to allow role "admin",
    but deny all other users.

    /Web.config:
    <authorization>
    <allow users="*" /> <!-- Allow all users -->
    </authorization>

    /Admin/Web.config:
    <authorization>
    <allow roles="admin"/>
    <deny users="*"/>
    </authorization>

    This setup prevents all users from accessing pages in the /Admin folder,
    even users whose IPrincipal.IsInRole("admin") implementation returns true.

    If I change /Amdin/Web.config to the below, it allows the "admin@mysite.com"
    user in:
    <authorization>
    <allow users="admin@mysite.com" roles="admin"/>
    <deny users="*"/>
    </authorization>

    Anyone ever seen this problem or have any idea what I am doing wrong?
    All examples I have seen appear to use the <allow roles="admin"/> approach.

    Thanks,
    -james

    --
    James McFarland :: SunPorch Structures Inc.
    James McFarland Guest

  2. Similar Questions and Discussions

    1. DESPERATE: FormsAuthentication Problem
      I am having a very perplexing problem with setting the user's roles. I have tried to figure this out for 2 days now. When the user logs in to the...
    2. FormsAuthentication.SignOut() problem
      Hi All, (thanks in advance for your time) I have a standard login.aspx page (UserName\Password). When the user successully sign in they are...
    3. Problem with FormsAuthentication.RedirectFromLoginPage
      I am having problem with redirection from http-https-http First an http application gets redirected to https application for authentication...
    4. FormsAuthentication client-side problem
      I'm using FormsAuthentication to secure access to a web site. The authentication process works correctly initially. The pages on the site have a...
    5. FormsAuthentication.Encrypt problem
      Hi, I have a strange problem. I get NULL reference out of Encrypt function. FormsAuthenticationTicket ticket = new...
  3. #2

    Default RE: FormsAuthentication Roles Problem

    Hello James,

    I think you should put the domain/machine name before "Admins". Also,
    please pay attention to that these names (including the group name) are
    case sensitive.

    Hope this help,

    Luke


    [MSFT] Guest

  4. #3

    Default RE: FormsAuthentication Roles Problem

    "[MSFT]" wrote:
    > Hello James,
    >
    > I think you should put the domain/machine name before "Admins". Also,
    > please pay attention to that these names (including the group name) are
    > case sensitive.
    >
    > Hope this help,
    >
    > Luke
    >
    >
    >
    Luke:
    I checked the case, and that all matches.
    Just to furhter clarify, I am not using AD or Windows Authentication, so the
    domain name/machine name are not relevant in my case.
    Does that make sense?

    Thanks,
    -james
    James McFarland Guest

  5. #4

    Default RE: FormsAuthentication Roles Problem

    Since you use Form authentication, can you explain more about how you
    implement IPrincipal.IsInRole and Application_AuthenticateRequest?
    Normally, we need grant roles in Application_AuthenticateRequest like:

    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
    Dim id as System.Web.Security.FormsIdentity
    id = HttpContext.Current.User.Identity

    Dim MyRoles(2) As String
    MyRoles(0) = "Manager"
    MyRoles(1) = "Admin"
    HttpContext.Current.User = new
    System.Security.Principal.GenericPrincipal(id,MyRo les)
    End if
    End if
    End sub


    Luke

    [MSFT] Guest

  6. #5

    Default RE: FormsAuthentication Roles Problem

    I think try MSFT advice first and see....
    And make sure u have Anonymous Access when using Forms Auth!
    With Web.Config its case sensitive so be careful...
    Enjoy!
    Patrick

    "[MSFT]" wrote:
    > Since you use Form authentication, can you explain more about how you
    > implement IPrincipal.IsInRole and Application_AuthenticateRequest?
    > Normally, we need grant roles in Application_AuthenticateRequest like:
    >
    > 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
    > Dim id as System.Web.Security.FormsIdentity
    > id = HttpContext.Current.User.Identity
    >
    > Dim MyRoles(2) As String
    > MyRoles(0) = "Manager"
    > MyRoles(1) = "Admin"
    > HttpContext.Current.User = new
    > System.Security.Principal.GenericPrincipal(id,MyRo les)
    > End if
    > End if
    > End sub
    >
    >
    > Luke
    >
    >
    Patrick.O.Ige Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139