Umbraco ApplicationEventHandler未为用户启动
我试图在CMS中创建新用户时向管理员发送电子邮件。但是,当我在VS中调试时创建一个新用户时,“umbraco.BusinessLogic.user.new+=user_new;”处的第一个断点永远不会被击中。我使用的是Umbraco的7.3.4版Umbraco ApplicationEventHandler未为用户启动,umbraco,Umbraco,我试图在CMS中创建新用户时向管理员发送电子邮件。但是,当我在VS中调试时创建一个新用户时,“umbraco.BusinessLogic.user.new+=user_new;”处的第一个断点永远不会被击中。我使用的是Umbraco的7.3.4版 using System; using System.Collections.Generic; using System.Linq; using System.Web using Umbraco.Core; using umbraco.Business
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web
using Umbraco.Core;
using umbraco.BusinessLogic;
namespace NewUserEmail
{
/// <summary>
/// Summary description for NewUserNotification
/// </summary>
public class NewUserNotification : ApplicationEventHandler
{
public NewUserNotification()
{
umbraco.BusinessLogic.User.New += User_New;
}
private void User_New(umbraco.BusinessLogic.User sender, EventArgs e)
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("nw@email.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web
使用Umbraco.Core;
使用umbraco.BusinessLogic;
名称空间NewUserEmail
{
///
///NewUserNotification的摘要说明
///
公共类NewUserNotification:ApplicationEventHandler
{
公共NewUserNotification()
{
umbraco.BusinessLogic.User.New+=用户\新;
}
私有无效用户\u新建(umbraco.BusinessLogic.User sender,EventArgs e)
{
System.Net.Mail.MailMessage message=新系统.Net.Mail.MailMessage();
message.To.Add(“nw@email.com");
message.Subject=“这是主题行”;
message.From=新系统.Net.Mail.MailAddress(“From@online.microsoft.com");
message.Body=“这是消息正文”;
System.Net.Mail.SmtpClient smtp=新的System.Net.Mail.SmtpClient(“您的SMTPHost”);
smtp.Send(message);
}
}
}
我认为,因为您使用的是ApplicationEventHandler,所以您需要重写ApplicationStarted方法,而不是使用构造函数
我使用的方式需要使用Umbraco.Core.Services代码>
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//I usually use Members for things like this but if you want user, it'll be UserService.SavedUser +=...
MemberService.Saved += User_New;
}
private void User_New(IMemberService sender, EventArgs e)
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("nw@email.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);
}
进一步阅读。我认为,因为您使用的是ApplicationEventHandler,所以您需要重写ApplicationStarted方法,而不是使用构造函数
我使用的方式需要使用Umbraco.Core.Services代码>
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//I usually use Members for things like this but if you want user, it'll be UserService.SavedUser +=...
MemberService.Saved += User_New;
}
private void User_New(IMemberService sender, EventArgs e)
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("nw@email.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);
}
进一步阅读。这很有效,我不知道UserService。非常感谢你!这很有效,我不知道用户服务。非常感谢你!