2009-02-05 3 views
0

Я довольно смущен. У меня есть элемент управления мастером createuser, который я использую с моими пользовательскими классами и классами ролей.C# createuser wizard OnDeactivate not firing

У меня есть шаг, чтобы пользователь-администратор мог создавать новых пользователей и назначать им их роли. Метод OnActivate запускается, но OnDeactivate - нет. Я поставил точки останова на оба метода и подтвердил, что он вообще не входит в метод. Я включил как разметку и код позади ниже, (извините, это немного долго я не хотел вырезать что-нибудь из упаковывают, что была проблема):

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> 
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/admin/default.aspx" 
    DisableCreatedUser="false" Font-Names="Verdana" BackColor="white" Font-Size="10pt" 
    BorderWidth="1px" BorderColor="#CCCC99" BorderStyle="Solid" CompleteSuccessText="The account has been successfully created." 
    UnknownErrorMessage="The account was not created. Please try again."> 
    <WizardSteps> 
     <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" Title="Step 1: Basic User Information" 
      OnDeactivate="UpdateCurrentLvl_OnDeactivate"> 
      <ContentTemplate> 
       <table style="font-size: 10pt; font-family: Verdana" border="0" width="400"> 
        <tr> 
         <td style="font-weight: bold; color: white; background-color: #6b696b" align="center" 
          colspan="2"> 
          Create Your UserID 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
          <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">UserID:</asp:Label></td> 
         <td> 
          <asp:TextBox ID="UserName" runat="server"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ToolTip="User Name is required." 
           ErrorMessage="User Name is required." ValidationGroup="CreateUserWizard1" ControlToValidate="UserName"> 
            *</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
          <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label></td> 
         <td> 
          <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ToolTip="Password is required." 
           ErrorMessage="Password is required." ValidationGroup="CreateUserWizard1" ControlToValidate="Password"> 
            *</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
          <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Re-Type Password:</asp:Label> 
         </td> 
         <td> 
          <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ToolTip="Confirm Password is required." 
           ErrorMessage="Confirm Password is required." ValidationGroup="CreateUserWizard1" 
           ControlToValidate="ConfirmPassword"> 
            *</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
          <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">Email:</asp:Label> 
         </td> 
         <td> 
          <asp:TextBox ID="Email" runat="server"></asp:TextBox>         
         </td> 
        </tr> 
       </table> 
       <br /> 
       <br /> 
       <table style="font-size: 10pt; font-family: Verdana" border="0" width="400"> 
        <tr> 
         <td style="font-weight: bold; color: white; background-color: #6b696b" align="center" 
          colspan="2"> 
          If You Forget Your Password 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
          Security Question: 
         </td> 
         <td> 
          <asp:DropDownList ID="Question" runat="server" Width="200"> 
           <asp:ListItem Text="[Select a Question]" /> 
           <asp:ListItem Text="Favorite Pet" /> 
           <asp:ListItem Text="Mother's Maiden Name" /> 
           <asp:ListItem Text="Who was your childhood hero?" /> 
           <asp:ListItem Text="Your favorite pasttime?" /> 
          </asp:DropDownList> 
          <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" InitialValue="[Select a Question]" 
           ControlToValidate="Question" ErrorMessage="Select a Security Question" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td align="right" width="170"> 
          Your Answer: 
         </td> 
         <td> 
          <asp:TextBox ID="Answer" runat="server"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" 
           ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
       </table> 
       <br /> 
       <br /> 
       <table style="font-size: 10pt; font-family: Verdana" border="0" width="400"> 
        <tr> 
         <td style="font-weight: bold; color: white; background-color: #6b696b" align="center" 
          colspan="2"> 
          Help Us Customize Your Experience 
         </td> 
        </tr> 
        <tr> 
         <td align="right" width="170"> 
          Set Level of the user:</td> 
         <td> 
          <asp:DropDownList ID="cLevel" runat="server"> 
           <asp:ListItem Text="[Select a Level]" /> 
           <asp:ListItem Text="1" /> 
           <asp:ListItem Text="2" /> 
           <asp:ListItem Text="3" /> 
          </asp:DropDownList> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" InitialValue="[Select a Level]" 
           ControlToValidate="cLevel" ErrorMessage="Select a Level" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td align="center" colspan="2"> 
          <asp:CompareValidator ID="PasswordCompare" runat="server" ErrorMessage="The Password and Confirmation Password must match." 
           ValidationGroup="CreateUserWizard1" ControlToValidate="ConfirmPassword" ControlToCompare="Password" 
           Display="Dynamic"> 
          </asp:CompareValidator> 
         </td> 
        </tr> 
        <tr> 
         <td style="color: red" align="center" colspan="2"> 
          <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> 
         </td> 
        </tr> 
       </table> 
      </ContentTemplate> 
     </asp:CreateUserWizardStep> 
     <asp:WizardStep runat="server" ID="wsAssignUserToRoles" AllowReturn="False" Title="Step 2: Assign User To Roles" 
      OnActivate="AssignUserToRoles_Activate" OnDeactivate="AssignUserToRoles_Deactivate"> 
      <table> 
       <tr> 
        <td> 
         Select one or more roles for the user:</td> 
       </tr> 
       <tr> 
        <td> 
         <asp:ListBox ID="AvailableRoles" runat="server" SelectionMode="Multiple" Height="104px" 
          Width="264px"></asp:ListBox> 
        </td> 
       </tr> 
      </table> 
     </asp:WizardStep> 
     <asp:CompleteWizardStep ID="CompleteWizardStep2" runat="server"> 
     </asp:CompleteWizardStep> 
    </WizardSteps> 
    <TitleTextStyle Font-Bold="True" BackColor="#6B696B" ForeColor="White"></TitleTextStyle> 
</asp:CreateUserWizard> 

Код за это:

public partial class admin_createuser : System.Web.UI.Page 
{ 
protected void Page_Load(object sender, EventArgs e) 
{ 

} 

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) 
{ 
    // Create an empty Profile for the newly created user 
    ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); 

    // Populate some Profile properties off of the create user wizard 
    p.CurrentLevel = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue); 

    // Save profile - must be done since we explicitly created it 
    p.Save(); 
} 

// Activate event fires when the user hits "next" in the CreateUserWizard 
public void AssignUserToRoles_Activate(object sender, EventArgs e) 
{ 
    // Databind list of roles in the role manager system to a listbox in the wizard 
    AvailableRoles.DataSource = Roles.GetAllRoles(); ; 
    AvailableRoles.DataBind(); 
} 

// Deactivate event fires when user hits "next" in the CreateUserWizard 
public void AssignUserToRoles_Deactivate(object sender, EventArgs e) 
{ 
    // Add user to all selected roles from the roles listbox 
    for (int i = 0; i < AvailableRoles.Items.Count; i++) 
    { 
     if (AvailableRoles.Items[i].Selected == true) 
      Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value); 
    } 
} 

//set the user level to the value set in the form as it has been inserted into the DB at this point. 
public void UpdateCurrentLvl_OnDeactivate(object sender, EventArgs e) 
{ 
    int level = Int32.Parse(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("clevel")).SelectedValue); 
    MyMembershipUser myUser = (MyMembershipUser)Membership.GetUser(CreateUserWizard1.UserName); 
    myUser.CurrentLVL = level; 
    Membership.UpdateUser(myUser); 
} 

}

ответ

0

Ну, я, кажется, нашли «в» ответ ... не знаю, почему это было бы дело.

У меня была страница мастера создания пользователя под /admin/createuser.aspx. Когда я помещаю это в корень веб-сайта, то есть ... /createuser.aspx все это сработало !!!!

не может это объяснить, но, похоже, это проблема. Очень странно!

..... редактировать

я говорил слишком рано. Кажется, это вопрос разрешений. Я думаю, что он хочет зарегистрировать меня (пользователя, создающего еще одну учетную запись) и войти в новый пользователь, которого пока нет в группах. Это означает, что они не могут получить доступ к какой-либо странице с защитой на ней в web.config, который у меня есть.

вопрос в том, как я могу остановить человека, который выйдет из системы и предоставить новые разрешения для пользователей?

Мое окончательное решение было использовать это заявление в управлении CreateUserWizard:

LoginCreatedUser="false" 

Он просто остановил пользователя от после входа в систему и удалить любые заботы вопросов разрешений, как в настоящее время вошли в систему пользователь должен иметь разрешений для этой страницы в первую очередь.

+0

Хотел бы также проголосовать за ваш ответ, но я новичок на сайте ... и у меня нет точек – AngelaG