Click to See Complete Forum and Search --> : Page.User.IsInRole(StringValue)
PPCC
Aug 11th, 2003, 08:13 AM
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:confused:
Cander
Aug 11th, 2003, 08:28 AM
you cant set. It returns true or false if the current user is in the Role you specifiy.
crpietschmann
Aug 12th, 2003, 09:25 AM
Yeah, it's like this
If Page.User.IsInRole("Managers") Then
' This user is in the Managers role.
End If
You can't set it. It is based on the network access rights that the currently logged in user has.
PPCC
Aug 13th, 2003, 03:43 AM
Originally posted by crpietschmann
Yeah, it's like this
If Page.User.IsInRole("Managers") Then
' This user is in the Managers role.
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
NighaŽe
Aug 14th, 2003, 03:25 AM
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.
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.