User.IsInRole not redirecting

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

  1. #1

    Default User.IsInRole not redirecting

    Hi there,

    I have been reading up on Authorization and role based security for a couple
    of days now, and am trying to implement this in my applications.

    I'm having a problem with my roles being reconized by using the
    user.isinrole("test") on the redirected page after the Login.

    for instance, here is my code after I log into the page:


    Dim test() As String = {"OEM", "test"}
    HttpContext.Current.User = New GenericPrincipal(User.Identity, test)
    FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, False)

    At this point if I break at the formsAuthentication.....I watch the
    User.isinrole("test") it shows up true, however, when I get redirected to
    the webform1.aspx page and also watch user.isinrole("test") then it is
    false.

    I'm really confused on what I need to do...I've tried the
    Threading.currentprincipal = new genericPrincipal(User.Identity, test) and
    that didn't work as well. The User.identity.isauthenticated does come over
    and also the User.identity.name comes over, it is just the
    user.isinrole("test") that does not come over.

    Any thoughts?

    You help is greatly appreciated...

    Thanks,
    Bob


    Bob Erwin Guest

  2. Similar Questions and Discussions

    1. User.IsInRole is always FALSE
      Hi, I have the following problem... Pre-requisites: Installation of an Asp.net webservice on a IIS5 server (win2k). Anonymous access is not...
    2. HttpContext.Current.User.IsInRole
      Hi, I have a problem when I am using the HttpContext.Current.User.IsInRole... This is my code: if (HttpContext.Current.User.IsInRole("Admin...
    3. Custom implementation for User.IsInRole??
      I have an app where im using FormsAuthenticaton, and doing my own authentication against a users table in my db. I have no problem actually getting...
    4. isInRole doesn't work for one user, but works for everyone else
      I have an ASP.NET/C# application in which I verify that the current user is a member of a list of roles before giving them access to particular...
    5. ASP.NET Context.User.IsInRole XP Problem
      Hi guys I am having a problem with the following line of code on Windows XP Pro. The variable userRole is a string depicting my role on the local...
  3. #2

    Default Re: User.IsInRole not redirecting

    You need to associate your principal with associated roles for each request
    that comes in. Once you have authenticated and redirected, typically all
    that will be passed along (automatically that is) is that the user has been
    authenticated. A common way of carrying the roles across multiple requests
    is, once authenticated, store the roles in the cookie that is issued to the
    client. Each request that comes in (via the Application_AuthenticateRequest
    event in Global.asax), you extract the roles, create your generic principal
    with the extracted roles, and associate that generic principal wih the
    current context . When doing this, you should also remember to encrypt the
    cookie.

    --
    - Paul Glavich


    "Bob Erwin" <berwin@msbob.com> wrote in message
    news:#9cbNiGsDHA.2828@tk2msftngp13.phx.gbl...
    > Hi there,
    >
    > I have been reading up on Authorization and role based security for a
    couple
    > of days now, and am trying to implement this in my applications.
    >
    > I'm having a problem with my roles being reconized by using the
    > user.isinrole("test") on the redirected page after the Login.
    >
    > for instance, here is my code after I log into the page:
    >
    >
    > Dim test() As String = {"OEM", "test"}
    > HttpContext.Current.User = New GenericPrincipal(User.Identity, test)
    > FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, False)
    >
    > At this point if I break at the formsAuthentication.....I watch the
    > User.isinrole("test") it shows up true, however, when I get redirected to
    > the webform1.aspx page and also watch user.isinrole("test") then it is
    > false.
    >
    > I'm really confused on what I need to do...I've tried the
    > Threading.currentprincipal = new genericPrincipal(User.Identity, test) and
    > that didn't work as well. The User.identity.isauthenticated does come
    over
    > and also the User.identity.name comes over, it is just the
    > user.isinrole("test") that does not come over.
    >
    > Any thoughts?
    >
    > You help is greatly appreciated...
    >
    > Thanks,
    > Bob
    >
    >

    Paul Glavich Guest

  4. #3

    Default Re: User.IsInRole not redirecting

    Hey Paul,

    Thanks for the response. I still have a question with this though. Yes you
    are correct that the authenticated user info is passed along automatically
    for me. So are you saying that Generic Principals assocated with that
    identity are *not* passed? Does that mean that I need to create a new
    generic principal and populate it each time I re-direct to a new page?

    Thanks,
    Bob

    "Paul Glavich" <glav@aspalliance.com-NOSPAM> wrote in message
    news:ugz5l2LsDHA.2060@TK2MSFTNGP10.phx.gbl...
    > You need to associate your principal with associated roles for each
    request
    > that comes in. Once you have authenticated and redirected, typically all
    > that will be passed along (automatically that is) is that the user has
    been
    > authenticated. A common way of carrying the roles across multiple requests
    > is, once authenticated, store the roles in the cookie that is issued to
    the
    > client. Each request that comes in (via the
    Application_AuthenticateRequest
    > event in Global.asax), you extract the roles, create your generic
    principal
    > with the extracted roles, and associate that generic principal wih the
    > current context . When doing this, you should also remember to encrypt the
    > cookie.
    >
    > --
    > - Paul Glavich
    >
    >
    > "Bob Erwin" <berwin@msbob.com> wrote in message
    > news:#9cbNiGsDHA.2828@tk2msftngp13.phx.gbl...
    > > Hi there,
    > >
    > > I have been reading up on Authorization and role based security for a
    > couple
    > > of days now, and am trying to implement this in my applications.
    > >
    > > I'm having a problem with my roles being reconized by using the
    > > user.isinrole("test") on the redirected page after the Login.
    > >
    > > for instance, here is my code after I log into the page:
    > >
    > >
    > > Dim test() As String = {"OEM", "test"}
    > > HttpContext.Current.User = New GenericPrincipal(User.Identity, test)
    > > FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, False)
    > >
    > > At this point if I break at the formsAuthentication.....I watch the
    > > User.isinrole("test") it shows up true, however, when I get redirected
    to
    > > the webform1.aspx page and also watch user.isinrole("test") then it is
    > > false.
    > >
    > > I'm really confused on what I need to do...I've tried the
    > > Threading.currentprincipal = new genericPrincipal(User.Identity, test)
    and
    > > that didn't work as well. The User.identity.isauthenticated does come
    > over
    > > and also the User.identity.name comes over, it is just the
    > > user.isinrole("test") that does not come over.
    > >
    > > Any thoughts?
    > >
    > > You help is greatly appreciated...
    > >
    > > Thanks,
    > > Bob
    > >
    > >
    >
    >

    Bob Erwin Guest

  5. #4

    Default Re: User.IsInRole not redirecting

    Hey,

    NeverMind on my last post. I was able to get this working based on the
    information you had provided.

    Just for those who are trying to do the same thing, I referenced:
    [url]http://www.codeproject.com/aspnet/formsroleauth.asp[/url] as well as other Deja
    Articles.

    And here is my code below:
    'in my login button code
    .........
    Dim AuthTicket = New FormsAuthenticationTicket(1, oUserInfo.EmailAddress,
    DateTime.Now, DateTime.Now.AddMinutes(30), False, oUserInfo.UserRoles,
    FormsAuthentication.FormsCookiePath)
    Dim hash As String = FormsAuthentication.Encrypt(AuthTicket)
    Dim cookie As New HttpCookie(FormsAuthentication.FormsCookieName, hash)
    Response.Cookies.Add(cookie)
    Response.Redirect(FormsAuthentication.GetRedirectU rl(oUserInfo.EmailAddress,
    False), False)
    end sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
    EventArgs)
    ' Fires upon attempting to authenticate the use
    If Request.IsAuthenticated Then
    If User.Identity.IsAuthenticated Then
    Dim id As FormsIdentity
    id = HttpContext.Current.User.Identity
    Dim AuthTicket As FormsAuthenticationTicket
    AuthTicket = id.Ticket
    Dim roles As String = AuthTicket.UserData
    Dim RoleArray As String()
    RoleArray = Split(roles, "|")
    HttpContext.Current.User = New
    GenericPrincipal(User.Identity, RoleArray)
    End If
    End If
    End Sub

    Thanks for your help...

    Bob

    "Paul Glavich" <glav@aspalliance.com-NOSPAM> wrote in message
    news:ugz5l2LsDHA.2060@TK2MSFTNGP10.phx.gbl...
    > You need to associate your principal with associated roles for each
    request
    > that comes in. Once you have authenticated and redirected, typically all
    > that will be passed along (automatically that is) is that the user has
    been
    > authenticated. A common way of carrying the roles across multiple requests
    > is, once authenticated, store the roles in the cookie that is issued to
    the
    > client. Each request that comes in (via the
    Application_AuthenticateRequest
    > event in Global.asax), you extract the roles, create your generic
    principal
    > with the extracted roles, and associate that generic principal wih the
    > current context . When doing this, you should also remember to encrypt the
    > cookie.
    >
    > --
    > - Paul Glavich
    >
    >
    > "Bob Erwin" <berwin@msbob.com> wrote in message
    > news:#9cbNiGsDHA.2828@tk2msftngp13.phx.gbl...
    > > Hi there,
    > >
    > > I have been reading up on Authorization and role based security for a
    > couple
    > > of days now, and am trying to implement this in my applications.
    > >
    > > I'm having a problem with my roles being reconized by using the
    > > user.isinrole("test") on the redirected page after the Login.
    > >
    > > for instance, here is my code after I log into the page:
    > >
    > >
    > > Dim test() As String = {"OEM", "test"}
    > > HttpContext.Current.User = New GenericPrincipal(User.Identity, test)
    > > FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, False)
    > >
    > > At this point if I break at the formsAuthentication.....I watch the
    > > User.isinrole("test") it shows up true, however, when I get redirected
    to
    > > the webform1.aspx page and also watch user.isinrole("test") then it is
    > > false.
    > >
    > > I'm really confused on what I need to do...I've tried the
    > > Threading.currentprincipal = new genericPrincipal(User.Identity, test)
    and
    > > that didn't work as well. The User.identity.isauthenticated does come
    > over
    > > and also the User.identity.name comes over, it is just the
    > > user.isinrole("test") that does not come over.
    > >
    > > Any thoughts?
    > >
    > > You help is greatly appreciated...
    > >
    > > Thanks,
    > > Bob
    > >
    > >
    >
    >

    Bob Erwin 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