Results 1 to 5 of 5

Thread: Page.User.IsInRole(StringValue)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Page.User.IsInRole(StringValue)

    How to Set & get value from Page.User.IsInRole(StringValue) as boolean.I am confuse with this statement.Can anybody explain this in short.

    Thanks ..

    Regards,


    PPCC

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you cant set. It returns true or false if the current user is in the Role you specifiy.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    Yeah, it's like this
    VB Code:
    1. If Page.User.IsInRole("Managers") Then
    2.      ' This user is in the Managers role.
    3. End If

    You can't set it. It is based on the network access rights that the currently logged in user has.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Ok But how do I ..

    Originally posted by crpietschmann
    Yeah, it's like this
    VB Code:
    1. If Page.User.IsInRole("Managers") Then
    2.      ' This user is in the Managers role.
    3. End If

    You can't set it. It is based on the network access rights that the currently logged in user has.
    Ok fine ..i can't set it but how do i differ the who's is the currenr role.
    Is it, if the login is succssful then Asp.net set the IsInRole value true..

    Please correct me ..

    PPCC

  5. #5
    Addicted Member Nigh™a®e's Avatar
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    175
    Hmmm, its possible to set the roles like u want.

    In your global.asax authentication request add following code.
    Based on Building Secure ASP.NET Applications book of microsoft.

    Create an autorization ticket at logon.
    on new page requests (call the authenticaterequest from global asax) the ticket will be used to create a new principal that will be used for the site.

    Code:
            Public Shared Sub AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
                'Load the Authentication Cookie
                Dim objCookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName)
    
                'Validate Cookie
                If objCookie Is Nothing Then
                    Return
                End If
    
                'Decrypt Authentication Ticket from Cookie
                Dim objTicket As FormsAuthenticationTicket
                Try
                    objTicket = FormsAuthentication.Decrypt(objCookie.Value)
                Catch ex As Exception
                    Return
                End Try
    
                'Validate Ticket
                If objTicket Is Nothing Then
                    Return
                End If
    
                'Load User Roles from the Ticket
                Dim varRoles As String() = objTicket.UserData.Split(CChar("|"))
    
                'Create the User Principal Object using the Authentication Ticket
                HttpContext.Current.User = New GenericPrincipal(New FormsIdentity(objTicket), varRoles)
            End Sub 
    
            Public Shared Sub Logon(ByVal Username As String, ByVal Password As String)
                Dim objUser As UserData
                Dim objRole As UserData
    
                Try
                    Dim varRole() As String
                    With New UserSystem
                        objUser = .GetUser(CType(CType(HttpContext.Current.Items("SiteInfo"), SiteData).Tables(SiteData.TABLE_SITES).Rows(0)(SiteData.FIELD_SITE_ID), System.Int64), Username, Password)
                        objRole = .GetUserInRole(objUser.User_ID(0))
    
                        ReDim varRole(objRole.UserInRolesTable.Rows.Count - 1)
                        For varRoleIndex As Integer = 0 To objRole.UserInRolesTable.Rows.Count - 1
                            varRole(varRoleIndex) = .GetRole(CType(CType(HttpContext.Current.Items("SiteInfo"), SiteData).Tables(SiteData.TABLE_SITES).Rows(0)(SiteData.FIELD_SITE_ID), System.Int64), CLng(objRole.UserInRole_Role(varRoleIndex))).Role_Name(0)
                        Next
                    End With
                    Dim objTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, Username, DateTime.Now, DateTime.Now.AddMinutes(60), False, String.Join("|", varRole))
                    Dim objTicketEncrypted As String = FormsAuthentication.Encrypt(objTicket)
                    Dim objCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, objTicketEncrypted)
    
                    'Append Cookie
                    HttpContext.Current.Response.Cookies.Add(objCookie)
                Catch ex As Exception
                    Throw New Exception("Exception verifying password. " & ex.Message)
                End Try
            End Sub
    
            Public Shared Sub Logoff()
                FormsAuthentication.SignOut()
            End Sub
    Greets Nightmare

Posting Permissions

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



Click Here to Expand Forum to Full Width