有谁使用过PasswordRecovery控件的?说说步骤啊?
在web.config中设置了mailSettings 不行.是自己要架设邮件服务吗?
或者有其他的解决方案?

解决方案 »

  1.   

    http://book.csdn.net/bookfiles/488/10048816972.shtmlhttp://msdn.microsoft.com/zh-cn/library/ms178335(VS.80).aspx
    http://msdn.microsoft.com/zh-cn/library/ms178341(VS.80).aspx在使用membership控件时,自动找回密码的PasswordRecovery控件时应该注意以下设置:不过,在些之前,web.config得另有配置。
    在system.web中的同级节点创建system.net节点,具体内容如下:
    <system.net>
    <mailSettings>
       <smtp deliveryMethod="Network" from="*@126.com">
           <network defaultCredentials="false" host="smtp.126.com" password="*" port="25" userName="*@126.com" />
       </smtp>
    </mailSettings>
       </system.net>注意:在mailSettings里面的各项设置不要出现空格,不要出现中文。例如:
    <system.net>
        <mailSettings>
          <smtp deliveryMethod="Network"   from="真是的邮箱名称@163.com">
            <network defaultCredentials="false" host="smtp.163.com" password="真是的密码" port="25" userName="真是的邮箱名称@163.com"   />
          </smtp>
        </mailSettings>
    </system.net>
    创建PasswordRecovery.aspx,放入PasswordRecovery控件 
    <asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
           </asp:PasswordRecovery>
      

  2.   


    在匿名用户可以访问的站点上创建或编辑 ASP.NET 网页(例如,RecoverPassword.aspx)。在经过身份验证的网站上,可以使用 location 配置元素指定可以匿名访问某页,如以下示例所示: 复制代码 
    <configuration>
      <location path="RecoverPassword.aspx">
        <system.web>
          <authorization>
            <allow users="?" />
          </authorization>
        </system.web>
      </location>  <system.web>
        <authentication mode="Forms" >
          <forms loginUrl="UserLogin.aspx" />
        </authentication>
        <authorization>
          <deny users="?" />
        </authorization>
      </system.web>
    </configuration> 将 PasswordRecovery 控件放置在页中,如以下示例所示: 复制代码 
    <asp:PasswordRecovery ID="PasswordRecovery1" Runat="server">
    </asp:PasswordRecovery> 或者,配置下列模板以自定义该 PasswordRecovery 控件的外观:UserNameTemplate、QuestionTemplate 和 SuccessTemplate。
      

  3.   

    编辑 PasswordRecovery 模板
    将一个 PasswordRecovery 控件添加到页面,如下面的代码示例所示。 复制代码 
    <asp:PasswordRecovery ID="PasswordRecovery1" Runat="server">
    </asp:PasswordRecovery> 您可以通过应用样式自定义 PasswordRecovery 控件的外观。使用属性(如 LabelStyle、HyperLinkStyle 和 TitleTextStyle 属性)可以将所有需要的样式应用到模板。若要自定义 PasswordRecovery 控件的内容,请继续执行下面的步骤以修改 PasswordRecovery 控件所使用的模板。创建一个 UserNameTemplate 模板以指定首次呈现控件时显示的标记和控件,如下面的代码示例所示。安全注意  
    该示例具有一个文本框,用于接受用户输入,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述。
     创建一个 QuestionTemplate 模板以指定当控件提示用户回答安全提示问题时显示的标记和控件,如下面的代码示例所示。安全注意  
    该示例具有一个文本框,用于接受用户输入,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述。
     
    <QuestionTemplate>
      <table border="0" cellpadding="1">
        <tr>
          <td>
            <table border="0" cellpadding="0">
              <tr>
                <td align="center" colspan="2">
                  Identity Confirmation</td>
              </tr>
              <tr>
                <td align="center" colspan="2">
                  Answer the following question to receive your password.</td>
              </tr>
              <tr>
                <td align="right">
                  User Name:</td>
                <td>
                  <asp:Literal ID="UserName" runat="server"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  Question:</td>
                <td>
                  <asp:Literal ID="Question" runat="server"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
                <td>
                  <asp:TextBox ID="Answer" runat="server"></asp:TextBox>
                  <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
                    ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
                </td>
              </tr>
              <tr>
                <td align="center" colspan="2" style="color: red">
                  <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </QuestionTemplate>
      

  4.   

    4 创建一个 QuestionTemplate 模板以指定当控件提示用户回答安全提示问题时显示的标记和控件,如下面的代码示例所示。安全注意  
    该示例具有一个文本框,用于接受用户输入,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述。
     <QuestionTemplate>
      <table border="0" cellpadding="1">
        <tr>
          <td>
            <table border="0" cellpadding="0">
              <tr>
                <td align="center" colspan="2">
                  Identity Confirmation</td>
              </tr>
              <tr>
                <td align="center" colspan="2">
                  Answer the following question to receive your password.</td>
              </tr>
              <tr>
                <td align="right">
                  User Name:</td>
                <td>
                  <asp:Literal ID="UserName" runat="server"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  Question:</td>
                <td>
                  <asp:Literal ID="Question" runat="server"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right">
                  <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
                <td>
                  <asp:TextBox ID="Answer" runat="server"></asp:TextBox>
                  <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
                    ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
                </td>
              </tr>
              <tr>
                <td align="center" colspan="2" style="color: red">
                  <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2">
                  <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </QuestionTemplate>
      

  5.   

    5. 创建一个 SuccessTemplate 模板以指定当用户成功找回密码时显示的标记和控件。下面的代码示例演示已定义 SuccessTemplate 模板的 PasswordRecovery 控件的标记。安全注意  
    该示例具有一个文本框,用于接受用户输入,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 HTML 元素。<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html  >
    <head runat="server">
        <title>Password Recovery All Templates Sample</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div title="All Templates Sample">
          <asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
            <QuestionTemplate>
              <table border="0" cellpadding="1">
                <tr>
                  <td>
                    <table border="0" cellpadding="0">
                      <tr>
                        <td align="center" colspan="2">
                          Identity Confirmation</td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2">
                          Answer the following question to receive your password.</td>
                      </tr>
                      <tr>
                        <td align="right">
                          User Name:</td>
                        <td>
                          <asp:Literal ID="UserName" runat="server"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          Question:</td>
                        <td>
                          <asp:Literal ID="Question" runat="server"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Answer:</asp:Label></td>
                        <td>
                          <asp:TextBox ID="Answer" runat="server"></asp:TextBox>
                          <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
                            ErrorMessage="Answer is required." ToolTip="Answer is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
                        </td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2" style="color: red">
                          <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </QuestionTemplate>
            <UserNameTemplate>
              <table border="0" cellpadding="1">
                <tr>
                  <td>
                    <table border="0" cellpadding="0">
                      <tr>
                        <td align="center" colspan="2">
                          Forgot Your Password?</td>
                      </tr>
                      <tr>
                        <td align="center" colspan="2">
                          Enter your User Name to receive your password.</td>
                      </tr>
                      <tr>
                        <td align="right">
                          <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></td>
                        <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" colspan="2" style="color: red">
                          <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" colspan="2">
                          <asp:Button ID="SubmitButton" runat="server" CommandName="Submit" Text="Submit" ValidationGroup="PasswordRecovery1" />
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </UserNameTemplate>
            <SuccessTemplate>
              <table border="0" cellpadding="1">
                <tr>
                  <td>
                    <table border="0" cellpadding="0">
                      <tr>
                        <td>
                          Your password has been sent to you.</td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </SuccessTemplate>
          </asp:PasswordRecovery>
        
        </div>
        </form>
    </body>
    </html>
     
      

  6.   

    指定字符串与电子邮件地址所要求的形式不符。
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.FormatException: 指定字符串与电子邮件地址所要求的形式不符。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
    [FormatException: 指定字符串与电子邮件地址所要求的形式不符。]
       System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) +934335
       System.Net.Mail.MailAddress.ParseValue(String address) +245
       System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +87
       System.Net.Mail.Message..ctor(String from, String to) +127
       System.Net.Mail.MailMessage..ctor(String from, String to) +117
       System.Web.UI.WebControls.MailDefinition.CreateMailMessage(String recipients, IDictionary replacements, String body, Control owner) +1538
       System.Web.UI.WebControls.LoginUtil.CreateMailMessage(String email, String userName, String password, MailDefinition mailDefinition, String defaultBody, Control owner) +183
       System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
       System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +653
       System.Web.UI.WebControls.PasswordRecovery.AttemptSendPassword() +66
       System.Web.UI.WebControls.PasswordRecovery.OnBubbleEvent(Object source, EventArgs e) +101
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746 
    请问出现这个错误是什么问题?就是在正确回答问题后出现的???