0

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()
            ListRoles.DataBind()
        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
                Response.Redirect("~/Admin/AddAdmin.aspx")

            ElseIf ListRoles.SelectedIndex = 1 Then
                Response.Redirect("~/Admin/AddDoctor.aspx")
            ElseIf ListRoles.SelectedIndex = 2 Then
                Response.Redirect("~/Admin/AddPatient.aspx")
            End If
        Next


    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>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

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

I need help asap:S

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
0

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


Sample.aspx

..
     <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem>Admin</asp:ListItem>
            <asp:ListItem>Member</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <br />
    </asp:Panel>
 

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
        oncreatinguser="CreateUserWizard1_CreatingUser">
        <WizardSteps>
            <asp:CreateUserWizardStep runat="server" />
            <asp:CompleteWizardStep runat="server" />
        </WizardSteps>
    </asp:CreateUserWizard>
..

.cs (There are two roles : Admin and Member

...
 protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
    {
        if(RadioButtonList1.SelectedValue=="Admin")
            System.Web.Security.Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");
        else
            System.Web.Security.Roles.AddUserToRole(CreateUserWizard1.UserName, "Member");
    }

...

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

Edited by __avd: Correct code tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.