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

Posted

技术标签:

【中文标题】通过 Createuserwizard 创建用户时控制台出错【英文标题】:Error in console when user is created via Createduserwizard 【发布时间】:2013-06-30 05:55:16 【问题描述】:

我通过 CreateUserWizard 创建用户 我已将 CreateUserWizard 包含在 Updatepanel 中。当创建用户并调用更新时,浏览器控制台显示错误并且更新面板未更新。

    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();


【问题讨论】:

进入您的代码 - 特别是 CreateUserWizard1_SendingMail1 方法,因为这是您在面板上调用 Update() 方法的地方。有可能其中的某些内容引发了错误,从而导致您收到消息。 谢谢蒂姆,是的,我检查过,但每件事都很顺利,结束块断点被命中,没有任何问题。 什么触发更新面板更新? 谢谢@SollyM 这个问题已经解决了。实际上在发送邮件完成执行后出现异常。因此,除了 Application_Error 之外,没有办法捕获该异常。因此,我转到 CreatedUserWizard 并尝试从那里手动发送邮件并捕获异常(如果有)以手动取消 createduser 并删除任何创建的用户。谢谢你的提问:) 甜蜜。然后把这个作为你的答案,这样这篇文章就可以完成了。 【参考方案1】:

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

【讨论】:

以上是关于通过 Createuserwizard 创建用户时控制台出错的主要内容,如果未能解决你的问题,请参考以下文章

防止asp中重复的手机号码:CreateUserWizard

MobilePin createuserwizard 不起作用?

SetPropertyValue 期间的 CreateUserWizard 错误:无法连接到 SQL Server 数据库

会员资格不被认可

Findcontrol 属性在 createUserWizard 中不起作用

删除用户名验证 createuserwizard