我有MVC5应用程序,它使用RazorEngine生成电子邮件。每封电子邮件都在cshtml模板中。模板中有数据被传递给它们,所以即使我这样做,缓存它们也没有真正的帮助。我还能做些什么来减少渲染时间吗?在Azure服务器上呈现需要几秒钟。
@{
ViewBag.Title = "_EmailResetPassword";
}
@{ var PasswordToken = Model.token; }
@{ var URLpath = Model.URLpath; }
@{ string link = string.Format("http://{0}/Account/ResetPassword/?tokenid={1}", URLpath, PasswordToken); }
<html>
<head>
<title></title>
<style type="text/css">
.auto-style1 {
text-align: center;
}
.auto-style2 {
background: white;
text-align: left;
font-size: 11.0pt;
font-family: Helvetica, sans-serif;
color: #4D4D4D;
}
</style>
</head>
<body>
<div class="auto-style1">
<h3 class="auto-style2">Dear @Model.FirstName,</h3>
<h3 class="auto-style2">We have reset your password at Eph Apparel for the username: @Model.UserName</h3>
<h3 class="auto-style2">Please click on the following link to create a new password:</h3>
<h3 style='text-align:center;background:white'><span lang=EN-CA
style='font-size:11.0pt;font-family:"Helvetica","sans-serif"'>
<a href="@link">Reset Password</a></span></h3>
<h3 style='text-align:center;background:white'><span lang=EN-CA
style='font-size:11.0pt;font-family:"Segoe UI","sans-serif";color:#4D4D4D'>LIKE US ON </span>
<span> <a href="https://www.facebook.com/ephapparel" target="_blank"><img alt="" width=25 height=22
src="http://ephoms-prod.azurewebsites.net/images/eph_graphics/fb_icon.png" ></a></span>
<span lang=EN-CA style='font-size:11.0pt;font-family:"Segoe UI","sans-serif";
color:#4D4D4D'> FOLLOW US ON </span><span lang=EN-CA></span>
<span><a href="https://www.twitter.com/ephApparel" target="_blank"><img alt="" width=25 height=23
src="http://ephoms-prod.azurewebsites.net/images/eph_graphics/twitter_icon.png"></a></span></h3>
<br>
<img alt="" src="http://ephoms-prod.azurewebsites.net/images/eph_graphics/eph_logo.png">
</div>
</body>
</html>代码背后:
private string ResetPassword(Customer oCustomer, string oToken)
{
string oURLpath = GetConfigSettingById(3);
string template = System.IO.File.ReadAllText(HostingEnvironment.MapPath("/bin/EmailTemplates/_EmailResetPassword.cshtml"));
string message = Razor.Parse(template, new { FirstName = oCustomer.FirstName, UserName = oCustomer.Email, token = oToken, URLpath = oURLpath }, "Reset");
return message;
}发布于 2014-06-27 13:09:07
private string ResetPassword(Customer oCustomer, string oToken)
{
string oURLpath = GetConfigSettingById(3);
string template = System.IO.File.ReadAllText(HostingEnvironment.MapPath("/bin/EmailTemplates/_EmailResetPassword.cshtml"));
string message = Razor.Parse(template, new { FirstName = oCustomer.FirstName, UserName = oCustomer.Email, token = oToken, URLpath = oURLpath });
return message;
}我要冒险说这就是你减速的地方.这类操作在站点上非常昂贵,特别是在其他地方运行时(即Azure)。此操作实际上是加载整个文件,然后每次重置密码时都填充它。
电子邮件一般有3种选择。
为了模板它,请执行以下操作:
给这个,或第三方api一个尝试,并让我们知道结果!(如果你在邮政方面需要帮助,问一个新的问题,我很乐意提供一些意见)
https://stackoverflow.com/questions/24437951
复制相似问题