Проверка электронной почты членства в ASP.NET
Попытка создать подтверждение электронной почты в C # на основеэта статья
Мы создали учетную запись jangosmtp для отправки электронного письма. Однако это некажется, работает.
Web.config:
Registration.aspx
Registration.aspx.cs:
namespace WebSite
{
public partial class Registration : System.Web.UI.Page
{
protected void CreateUserWizard1_SendingMail(object sender, MailMessageEventArgs e)
{
//Send an email to the address on file
MembershipUser userInfo = Membership.GetUser(CreateUserWizard1.UserName);
//Construct the verification URL
string verifyUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Page.ResolveUrl("~/Verify.aspx?ID=" + userInfo.ProviderUserKey.ToString());
//Replace placeholder with verifyUrl value
e.Message.Body = e.Message.Body.Replace("", verifyUrl);
}
}
}
NewAccountTemplate.htm
Steps to activate your account...
Welcome to My Website!
<p>
Hello, . You are receiving this email because you recently created a new account at my
site. Before you can login, however, you need to first visit the following link:</p>
<p>
<a href="%VerifyUrl%"></a></p>
<p>
After visiting the above link you can log into the site!</p>
<p>
If you have any problems verifying your account, please reply to this email to
get assistance.</p>
<p>
Thanks!</p>
Verify.aspx.cs:
namespace WebSite
{
public partial class Verify : Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Make sure that a valid query string value was passed through
if (string.IsNullOrEmpty(Request.QueryString["ID"]) || !Regex.IsMatch(Request.QueryString["ID"], "[0-9a-f]{8}\\-([0-9a-f]{4}\\-){3}[0-9a-f]{12}"))
{
InformationLabel.Text = "An invalid ID value was passed in through the querystring.";
} else {
//ID exists and is kosher, see if this user is already approved
//Get the ID sent in the querystring
Guid userId = new Guid(Request.QueryString["ID"]);
//Get information about the user
MembershipUser userInfo = Membership.GetUser(userId);
if (userInfo == null) {
//Could not find user!
InformationLabel.Text = "The user account could not be found in the membership database.";
} else {
//User is valid, approve them
userInfo.IsApproved = true;
Membership.UpdateUser(userInfo);
//Display a message
InformationLabel.Text = "Your account has been verified and you can now log into the site.";
}
}
}
}
}
Что касается меня, то есть две вещи, которые, как я предполагаю, не заставляют его работать.
Как он узнает, что отправил сообщение NewAccountTemplate.htm? ОБНОВЛЕНИЕ Ааа, я вижу, где это происходит в createuserwizard1 сейчас. Все еще получаю это сообщение об ошибке.На NewAccountTemplate.htm я получаю предупреждение:Предупреждение '<% VerifyUrl%> ' не был найден.
Какие'идет не так? Я пропускаю что-то.
ОБНОВЛЕНИЕ 2:
Если я добавлю onsendingmail = "CreateUserWizard1_SendingMail» Он генерирует ссылку, однако ссылка не работает, потому что пользователь никогда не добавляется в базу данных, которую я проверил. Поэтому, когда я нажимаю на ссылку в электронном письме, появляется сообщение о плохом запросе, потому что нет пользователя с таким идентификатором. Если я удалю эту строку кода, пользователь будет создан, но ссылка не сгенерирована: /