- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试在我的 MVC5 网站上使用 Postal。当我托管我的网页时,一个子站点即 http://localhost/Subsite我收到错误信息
我已将其调试到创建 ControllerContext 时 HttpContext 未正确设置。由于我从 Hangfire 运行 Postal,因此 HttpContext.Current 始终为空。 Postal 使用以下代码创建 ContollerContext。
ControllerContext CreateControllerContext()
{
// A dummy HttpContextBase that is enough to allow the view to be rendered.
var httpContext = new HttpContextWrapper(
new HttpContext(
new HttpRequest("", UrlRoot(), ""),
new HttpResponse(TextWriter.Null)
)
);
var routeData = new RouteData();
routeData.Values["controller"] = EmailViewDirectoryName;
var requestContext = new RequestContext(httpContext, routeData);
var stubController = new StubController();
var controllerContext = new ControllerContext(requestContext, stubController);
stubController.ControllerContext = controllerContext;
return controllerContext;
}
string UrlRoot()
{
var httpContext = HttpContext.Current;
if (httpContext == null)
{
return "http://localhost";
}
return httpContext.Request.Url.GetLeftPart(UriPartial.Authority) +
httpContext.Request.ApplicationPath;
}
我如何指定 UrlRoot,而不是根据我的子站点拉取默认的 localhost 来拉取它?
最佳答案
我按照这里的指示操作 http://docs.hangfire.io/en/latest/tutorials/send-email.html发送我的电子邮件。教程中的方法如下
public static void NotifyNewComment(int commentId)
{
// Prepare Postal classes to work outside of ASP.NET request
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var emailService = new EmailService(engines);
// Get comment and send a notification.
using (var db = new MailerDbContext())
{
var comment = db.Comments.Find(commentId);
var email = new NewCommentEmail
{
To = "yourmail@example.com",
UserName = comment.UserName,
Comment = comment.Text
};
emailService.Send(email);
}
}
我发现问题是 FileSystemRazorViewEngine 没有被邮政使用。为了让它工作,我必须确保 FileSystemRazorViewEngine 是可用的第一个引擎。然后我删除了它,因为我不希望它成为默认引擎。以下是我更新的方法。
public static void NotifyNewComment(int commentId)
{
// Prepare Postal classes to work outside of ASP.NET request
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var eng = new FileSystemRazorViewEngine(viewsPath));
ViewEngines.Engines.Insert(0, eng);
var emailService = new EmailService(engines);
// Get comment and send a notification.
using (var db = new MailerDbContext())
{
var comment = db.Comments.Find(commentId);
var email = new NewCommentEmail
{
To = "yourmail@example.com",
UserName = comment.UserName,
Comment = comment.Text
};
emailService.Send(email);
ViewEngines.Engines.RemoveAt(0)
}
}
关于asp.net-mvc - 在子站点中使用 Postal 和 Hangfire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389505/
我想在数据库中存储英国邮政编码。存储那些没有空格的邮政编码可以吗? 最佳答案 可以存储不带空格的邮政编码,但绝对建议在显示/输出时正确格式化它们。 您可以查看邮政编码的允许格式 here .空格后始终
如果用户没有用空格写邮政编码,有没有办法知道在英国邮政编码中空格必须在哪里? 例如,如果输入是:EC1A1BB, W1A0AX, M11AE, B338TH, CR26XH, DN551PT那么输出必
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
我不想重新发明轮子。 是否有人知道在加拿大邮政的“查找邮政编码”页面中使用 php/curl 代码填充地址数据http://www.canadapost.ca/cpotools/apps/fpc/pe
我有两个分离的组件在一个页面上运行,并且希望使用 Postal.js 在单击一个组件到另一个组件时发送消息。 当单击第一个组件时,它会发布帖子: postal.publish({ channel:
我正在尝试使用 Postal 从我的 Gmail 帐户发送电子邮件: dynamic email = new Email("Appointment"); email.To = "sergiotapia
我在跑 Postal from a service .我的@Message 有 html。 @Html.Raw 不可用。当 Postal 运行我的模板化 View 时,我得到 HtmlEncoded
我一直在尝试在我的 MVC5 网站上使用 Postal。当我托管我的网页时,一个子站点即 http://localhost/Subsite我收到错误信息 虚拟路径“/”映射到另一个应用程序,这是不允许
当我使用 Postal 使用 Layout 发送电子邮件时,似乎没有解析标题并将其包含在邮件消息中。 View /电子邮件/_ViewStart.cshtml @{ Layout = "~/Views
我正在尝试在我的reactJs站点中使用postal.js订阅/发布数据,我目前正在这样做。谁能告诉我如何推送选定的 id,我认为 loadContacts 方法正在将值重置为 false: 这是我的
我的项目托管在 Azure 上,我想每天早上向忘记完成应用程序中某些任务的用户发送一封电子邮件。 我已经建立了电子邮件(使用邮政发送)。如果我运行该函数本身,电子邮件将按预期发送。 我已将 Azure
我正在使用此 API 调用 Google Maps 来获取邮政编码的纬度和经度 http://maps.googleapis.com/maps/api/geocode/json?address=234
有几种技巧可以在移动设备上为 HTML 5 输入(即 标签)显示不同的键盘。 例如,有些记录在 Apple 的网站上,Configuring the Keyboard for Web Views .
我在项目中使用 POSTAL MVC 时遇到问题。我的托管服务公司要求我在代码中而不是在 Web 配置中设置 smtp 客户端配置。 怎么做? 希望有人能给我一个解决方案 谢谢。 最佳答案 我遇到了同
在加拿大的许多政府网站上,他们有一个功能,他们只能通过邮政编码和街道名称知道您的地址。 当你在谷歌地图上搜索邮政编码时,这个邮政编码所覆盖的区域就被覆盖了。 但是查看 google map API,我
我是一名优秀的程序员,十分优秀!