【发布时间】:2014-06-26 18:47:11
【问题描述】:
我有使用 RazorEngine 生成电子邮件的 MVC5 应用程序。每封电子邮件都在一个 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;
}
【问题讨论】:
-
RazorEngine 可能会很慢,这取决于您在做什么......我们可以看看一些代码来帮助评估吗?
-
除了其他两个非常合适的问题外,您是否在 Visual Studio 中使用调试在本地运行此程序?如果您是,那么在本地开发过程中某事有多“慢”对任何事情都没有影响。性能测试的时间是在生产就绪的服务器上。
-
这是在 Azure 上的生产服务器上运行的。渲染视图需要几秒钟。