代码之家  ›  专栏  ›  技术社区  ›  DisgruntledGoat

ASP密码恢复不工作

  •  4
  • DisgruntledGoat  · 技术社区  · 14 年前

    I have an ASP PasswordRecovery module on a page, the code comes up like this:

    <asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
        <MailDefinition From="[email]">
        </MailDefinition>
    </asp:PasswordRecovery>
    

    但是,当我提交表单时,我只是收到了消息, “我们无法访问您的信息。请再试一次。”

    我看见了 this question 并确保将这些属性添加到我的web.config中:

    <providers>
        <remove name="CustomizedMembershipProvider"/>
        <add name="CustomizedMembershipProvider"
            type="System.Web.Security.SqlMembershipProvider"
            connectionStringName="MessageBank"
            applicationName="MessageBank"
            minRequiredPasswordLength="6"
            minRequiredNonalphanumericCharacters="0"
            requiresQuestionAndAnswer="false"
            enablePasswordReset="true"
            enablePasswordRetrieval="false" />
    </providers>
    

    这封邮件工作得很好,因为应用程序每天都定期发送电子邮件。但它不会出于某种原因发送恢复电子邮件。

    以下是相关的web.config部分:

    <mailSettings>
        <smtp from="[email]">
            <network host="[host]" password="[password]" userName="[username]"/>
        </smtp>
    </mailSettings>
    

    UPDATE: I added a function to handle the "SendingMail" event:

    Protected Sub PasswordRecovery_submit(ByVal sender As Object, ByVal e As WebControls.MailMessageEventArgs) Handles PasswordRecovery.SendingMail
    

    我在这个函数中添加了一个断点,但它从未到达,上面的错误消息只是在应用程序中出现。还有其他调试方法吗?

    3 回复  |  直到 14 年前
        1
  •  1
  •   Brian Scott    14 年前

    你记得在web.config中声明你的smtp部分吗?默认情况下,密码恢复控件在执行过程中使用它。

    <system.net>
    <mailSettings>
    <smtp deliveryMethod="Network">
    <network
    defaultCredentials="True"
    host="localhost"
    port="25"
    from="webmaster@mydomain.com"/>
    </smtp>
    </mailSettings>
    </system.net>
    
        2
  •  1
  •   Hugh Jeffner    14 年前

    该错误消息是默认的 UserNameFailureText

    Are you sure you are entering a valid user name?

        3
  •  1
  •   DisgruntledGoat    14 年前

    Here is how I solved the problem. As mentioned in the comments on Brian's answer, our app is using a custom email function (not 100% sure why but the regular SMTP stuff just doesn't work). Anyway, you can simply hijack the PasswordRecovery.SendingMail 事件:

    Protected Sub PasswordRecovery_submit(ByVal sender As Object, ByVal e As WebControls.MailMessageEventArgs) Handles PasswordRecovery.SendingMail
        ' do custom email sending here, using the variables in e.Message 
    
        e.Cancel = False
    End Sub