Hi.
(First sry my english)
Im new to this and is trying to get a login script working, its working fine, but now i have a new problem, i have a field im my DB thats called "urole" in that i have 3 roles, Admin, Co-Admin, User.
How can i use something like this on a page.
I have this script on my login pageCode:If Roles.IsUserInRole("Admin") Then Label1.Text = User.Identity.Name + " is an Admin" Else Label1.Text = User.Identity.Name + " is NOT in an Admin" End If
and then i have this on my default page, thats shows the info from an user, now i just want to show the role (urole) and then use an "If Roles.IsUserInRole" event so i can show some diffrent thing if admin, co-admin or UserCode:Imports System.IO Imports System.Data Imports System.Data.OleDb Imports System.Web.Configuration Partial Class DbLogin Inherits System.Web.UI.Page Public Function Myauthenticate(ByVal username As String, ByVal userPassword As String) As Boolean Using conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString) Try conn.Open() Catch ex As Exception ' Log the error but don't ' display any details to the user System.Diagnostics.Debug.WriteLine("Exception: " & ex.Message) ' Login failed Return False End Try Try Using cmd As New OleDbCommand() cmd.Connection = conn cmd.CommandText = "" & _ "SELECT urole " & _ "FROM usersdatabase " & _ "WHERE uname=@userName " & _ "AND pwd=@passWord" cmd.Parameters.AddWithValue("@userName", username) cmd.Parameters.AddWithValue("@passWord", userPassword) Dim Retuser As String = cmd.ExecuteScalar().ToString() If Retuser IsNot Nothing Then Return True Else Return False End If End Using Catch ex As Exception ' Log the error but don't ' display any details to the user System.Diagnostics.Debug.WriteLine("Exception: " & ex.Message) ' Login failed Return False Finally conn.Close() End Try End Using Dim MyConfig As Configuration = WebConfigurationManager.OpenWebConfiguration("./") Dim SystemWeb As ConfigurationSectionGroup = MyConfig.SectionGroups("system.web") Dim AuthSec As AuthenticationSection = DirectCast(SystemWeb.Sections("authentication"), AuthenticationSection) AuthSec.Forms.Credentials.Users.Add(New FormsAuthenticationUser(UsernameText.Text, PasswordText.Text)) MyConfig.Save() End Function Protected Sub LoginAction_Click( ByVal sender As Object, ByVal e As System.EventArgs ) Handles LoginAction.Click Page.Validate() If Not Page.IsValid Then Return If Me.Myauthenticate(UsernameText.Text, PasswordText.Text) Then FormsAuthentication.RedirectFromLoginPage(UsernameText.Text, False) Else LegendStatus.Text = "Invalid username or password!" End If End Sub End Class
Hope someone can help me, im new to this and cant get this fixed.Code:Imports System.IO Imports System.Web.Security Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim htmlString As New StringBuilder() ' Has the request been authenticated? If Request.IsAuthenticated Then ' Display generic identity information. ' This is always available, regardless of the type of ' authentication. htmlString.Append("<h3>Generic User Information</h3>") htmlString.Append("<b>name: </b>") htmlString.Append(User.Identity.Name) htmlString.Append("<br><b>Authenticated With: </b>") htmlString.Append(User.Identity.AuthenticationType) htmlString.Append("<br><br>") End If ' Was forms authentication used? If TypeOf User.Identity Is FormsIdentity Then ' Get the ticket. Dim ticket As FormsAuthenticationTicket = (DirectCast(User.Identity, FormsIdentity)).Ticket htmlString.Append("<h3>Ticket User Information</h3>") htmlString.Append("<b>Name: </b>") htmlString.Append(ticket.Name) htmlString.Append("<br><b>Issued at: </b>") htmlString.Append(ticket.IssueDate) htmlString.Append("<br><b>Expires at: </b>") htmlString.Append(ticket.Expiration) htmlString.Append("<br><b>Cookie version: </b>") htmlString.Append(ticket.Version) ' Display the information. LegendInfo.Text = htmlString.ToString() End If End Sub Protected Sub SignOutAction_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SignOutAction.Click FormsAuthentication.SignOut() FormsAuthentication.RedirectToLoginPage() End Sub End Class
(The aboved is working fine, but its not showing the urole/Role of an user)




Reply With Quote