Ok guys, im here with a problem
The thing is that ive created a website for a doctors hospital.Now the admin staff are allowed to create new patient and add new staff to the database. I have two databases right now.The aspnet membership data base and another one that has been created for the hospital. Now whenever i login as an admin and create new staff and patient usernames and assign their roles, somehow those are not saved in the aspnet database and neither are the user names saved in the respective tables(i.e if role is patient the username should be saved in the patient table etc).i have the code, but i dont know why its not saving the usernames or assigning the roles. I logged out and tried logining in as the users that i created but im not redirected to the correct page instead i stay on the login page. The problem is with the role assignment and i dont know how to fix it. The code is in Visual Basic:

This is the VB code:

Partial Class Admin_Regi
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If User.IsInRole("Admin") Then
        '    Response.Redirect("~/Admin/AdminDefault.aspx")
        'End If
        If Not Page.IsPostBack Then

            Dim SpecifyRolesStep As WizardStep = TryCast(RegisterUser.FindControl("RolesStep"), WizardStep)

            'Dim RoleList As CheckBoxList = TryCast(SpecifyRolesStep.FindControl("ListOfRoles"), CheckBoxList)

            ListRoles.DataSource = Roles.GetAllRoles()
        End If

    End Sub

    Protected Sub RegisterPeopleWithRoles_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterUser.CreatedUser
        Dim SpecifyRolesStep As WizardStep = TryCast(RegisterUser.FindControl("RolesStep"), WizardStep)

        For Each li As ListItem In ListRoles.Items
            If li.Selected Then
                Roles.AddUserToRole(RegisterUser.UserName, li.Text)
            End If
            Session("Customer") = RegisterUser.UserName

            If ListRoles.SelectedIndex = 0 Then

            ElseIf ListRoles.SelectedIndex = 1 Then
            ElseIf ListRoles.SelectedIndex = 2 Then
            End If

    End Sub

    Protected Sub ListOfRoles_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListRoles.SelectedIndexChanged
        Session("Rolesss") = ListRoles.SelectedItem.ToString()
    End Sub
End Class

This is the wizard code:

<%@ Page Title="" Language="VB" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="false" CodeFile="Regi.aspx.vb" Inherits="Admin_Regi" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

        Create a User Account</h1>
    <br />
    <asp:CreateUserWizard ID="RegisterUser" runat="server" 
        LoginCreatedUser="False" style="margin-top:50px;margin-left:234px;" Width="313px">
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
            <asp:WizardStep ID="RolesStep" runat="server" 
                StepType="Step" Title="my Roles">
                <asp:CheckBoxList ID="ListRoles" runat="server">
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

I need help asap:S

You need to assign role while creating a new user. Handle the CreatingUser event of CreateUserWizard.


     <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <br />
        <br />

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
            <asp:CreateUserWizardStep runat="server" />
            <asp:CompleteWizardStep runat="server" />

.cs (There are two roles : Admin and Member

 protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
            System.Web.Security.Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");
            System.Web.Security.Roles.AddUserToRole(CreateUserWizard1.UserName, "Member");


Read article about ASP.NET authentication & authorization - http://www.4guysfromrolla.com/webtech/110701-1.shtml

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.