通过Createuserwizard创建用户时控制台出错

时间:2013-06-30 05:55:17

标签: c# asp.net asp.net-membership updatepanel createuserwizard

我通过CreateUserWizard创建了一个用户我在Updatepanel中附上了CreateUserWizard。创建用户并调用更新时,浏览器控制台显示错误,并且更新面板未更新。

    Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 ScriptResource.axd:513


          <asp:UpdatePanel UpdateMode="Conditional"  runat="server" ID="UpdatePanelCreateUser">
                <ContentTemplate>
                    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" CompleteSuccessText="Successful. Confirmation mail has been sent to the Email address. Follow the link to confirm your account."
                        DisableCreatedUser="true" LoginCreatedUser="false" OnCreatedUser="CreateUserWizard1_CreatedUser"
                        OnCreatingUser="CreateUserWizard1_CreatingUser" 
                        onsendingmail="CreateUserWizard1_SendingMail1" >
                        <MailDefinition BodyFileName="~/MailFile.txt" From="spiralswhirls@yahoo.com" >

                        </MailDefinition>
                        <WizardSteps>
                            <asp:CreateUserWizardStep runat="server">
                                <ContentTemplate>
                                    <table border="0">
                                        <tr>
                                            <td align="center" colspan="2">
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName" Visible="false">User Name:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="UserName" runat="server" Visible="false"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="Label2" runat="server">First Name:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TextBoxFirstName" runat="server"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxFirstName"
                                                    ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="LabelLastName" runat="server">Last Name:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TextBoxLastName" runat="server"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxLastName"
                                                    ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</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" ControlToValidate="Password"
                                                    ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
                                                    ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
                                                    ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right">
                                                <asp:Label ID="LabelSex" runat="server" AssociatedControlID="DropDownListSex">Sex:</asp:Label>
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="DropDownListSex" runat="server">
                                                    <asp:ListItem>Male</asp:ListItem>
                                                    <asp:ListItem>Female</asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DropDownListSex"
                                                    ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" style="padding-left: 10px;">
                                                <BotDetect:Captcha ID="Captcha1" runat="server" CodeLength="7" />
                                                <asp:TextBox ID="TextBox1" runat="server" Width="280px"></asp:TextBox>
                                                <div>
                                                    <asp:Label runat="server" ID="LabelCaptcha" Style="font-size: 11px;"></asp:Label>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="2">
                                                <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                                    ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                                    ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="2" style="color: Red;">
                                                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                            </td>
                                        </tr>
                                    </table>
                                </ContentTemplate>
                            </asp:CreateUserWizardStep>
                            <asp:CompleteWizardStep runat="server" />
                        </WizardSteps>
                    </asp:CreateUserWizard>
                </ContentTemplate>
            </asp:UpdatePanel>

CreatedUser事件

     protected void CreateUserWizard1_CreatedUser(object sender, EventArgs  e)
    {
    TextBox textboxemail = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); 
    MembershipUser user = Membership.GetUser(textboxemail.Text);
    Guid userid = (Guid)user.ProviderUserKey;
    TextBox firstname = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFirstName");
    TextBox lastname = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxLastName");
    DropDownList sex = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListSex");
    ProfileDataAccess.SaveUserName(firstname.Text, null, lastname.Text, Convert.ToString (userid));
    ProfileDataAccess.SaveSex(sex.SelectedValue, Convert.ToString(userid));
    ProfileDataAccess.SetProfilePictureForNewUser(userid, 0);
    //CreateUserWizard1.MailDefinition.From = "autogenerated@studentjoin.com";
    Label labelCaptcha = (Label)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LabelCaptcha");
    labelCaptcha.Text = "";
}

发送邮件事件

    protected void CreateUserWizard1_SendingMail1(object sender, MailMessageEventArgs e)
  { 
   TextBox textboxemail = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"); 
   MembershipUser user = Membership.GetUser(textboxemail.Text);
   Guid userid = (Guid)user.ProviderUserKey;
   string verificationurl="http://www.spiralsnet.com/Login.aspx?NewUserId="+userid.ToString ();
   e.Message.IsBodyHtml = true;
   e.Message.From = new System.Net.Mail.MailAddress("SpiralsWhirls@yahoo.com", "SpiralsNet");
   e.Message.Body = e.Message.Body.Replace("<%VU%>", verificationurl);

   UpdatePanelCreateUser.Update();

}

}

1 个答案:

答案 0 :(得分:0)

问题已经解决。实际上sendingmail执行完毕后有一个例外。所以除了Application_Error之外没有办法捕捉到这个异常。所以我转移到CreatedUser并尝试从那里手动发送邮件并捕获异常(如果有)手动取消createduser并删除任何创建的用户。