指定的字符串不是电子邮件地址所需的格式。任何修复?

时间:2014-10-21 12:53:01

标签: mysql asp.net membership password-recovery

我试图在我的网站上设置一个恢复密码页面,但每次都出现错误:"指定的字符串不是电子邮件地址所需的格式。 "

我输入用户名,点击提交。它带我到秘密的问答页面,我输入答案并点击提交。然后,它显示了有关电子邮件的错误。它有解决方法吗?

这是我的网页代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageTest.master" AutoEventWireup="true" CodeFile="forgotpass.aspx.cs" Inherits="forgotpass" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<center><b>
    <asp:PasswordRecovery ID="PasswordRecovery1" runat="server" 
        TextLayout="TextOnTop" 
        UserNameInstructionText="הכנס את שם המשתמש שלך כדי לקבל את סיסמתך" 
        UserNameLabelText="שם משתמש:" UserNameTitleText="שכחת את סיסמתך?">
        <UserNameTemplate>
            <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
                <tr>
                    <td>
                        <table cellpadding="0">
                            <tr>
                                <td align="center">
                                    שכחת את סיסמתך?</td>
                            </tr>
                            <tr>
                                <td align="center">
                                    הכנס את שם המשתמש שלך כדי לקבל את סיסמתך</td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">שם משתמש:</asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                        ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                        ToolTip="User Name is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" style="color:Red;">
                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="אפס סיסמא" 
                                        ValidationGroup="PasswordRecovery1" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </UserNameTemplate>
    </asp:PasswordRecovery>
</b></center>
</asp:Content>

1 个答案:

答案 0 :(得分:1)

您必须在控件的MailDefinition中指定正确的From。例如:

<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
     <MailDefinition From="...@gmail.com" Subject="ResetPassword"
      Priority="High"/>
</asp:PasswordRecovery>

无论是这种方式,还是来自您的代码隐藏。

另外,您需要确保您的会员提供商返回的EmailAddress是有效的。

此外,请确保您的应用程序已正确配置为发送电子邮件。检查web.config文件,system.net - &gt;部分。 mailSettings:

<system.net>
    <mailSettings>
        <smtp>
            <network host="host.domain.com" userName="..." password="..." />
        </smtp>
    </mailSettings>
</system.net>

如果您的SMTP服务器接受来自您IP地址的未经授权的连接,则可以删除userNamepassword

作为快速修复,您可以附加到控件的SendingMail事件(请参阅http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.passwordrecovery.sendingmail(v=vs.110).aspx)并显示一条很好的错误消息并使用以下命令取消消息:

e.Cancel = true; // where e is the MailMessageEventHandler

但如果所有验证都已就绪并且所有设置都正常,那么无论如何都不应该有这种情况。