ASP PasswordRecovery not working
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>
However, when I submit the form I just get the message, "We were unable to access your information. Please try again."
I saw this question and made sure to add those attributes to 开发者_StackOverflow社区my web.config here:
<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>
The email is working fine because the app sends emails regularly throughout the day. But it's not sending recovery emails for some reason.
Here's the relevant web.config section:
<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
I added a break point in this function but it is never reached, the above error message just comes up in the app. Any other ways to debug what's going wrong?
Have you remembered to declare your smtp section in your web.config? By default the password recovery control uses this during it's execution.
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
defaultCredentials="True"
host="localhost"
port="25"
from="webmaster@mydomain.com"/>
</smtp>
</mailSettings>
</system.net>
That error message is the default UserNameFailureText
Are you sure you are entering a valid user name?
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
event:
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
精彩评论