我正在用c# .net开发一个企业应用程序。在系统中生成了许多pdf文档。我使用罗塔蒂瓦进行pdf处理。有一个pdf使用用户创建的模板在系统中。系统从系统中获取数据,用服务器的动态值替换模板变量,并下载pdf。这个特定的pdf在我的本地和开发服务器上运行良好,但是在生产服务器上失败。如果有人能帮忙我会很高兴的。我已经附上了错误和代码。请看一下。
public ActionResult GenerateRedemptionLetterGift(int id, int templateId)
{
try
{
int RedTempId = templateId; //Convert.ToInt32(Request.QueryString["templateId"]);
int type = 2;
RedemptionCode RedemptionObj = new RedemptionCode();
RedemptionObj = BlObj.GetRedemptionDetail(id);
return new Rotativa.MVC.ActionAsPdf("ReturnTemplate", new { id, RedTempId, type }) { FileName = "Redemption_Letter_" + RedemptionObj.Id.ToString() + ".pdf" };
}
catch (Exception ex)
{
throw new Exception("Main Method", ex);
}
}在这里,我将函数ReturnTemplate称为ActionAsPdf,在该函数中,在用户创建的模板中获取和替换所有数据。
public ActionResult ReturnTemplate(int id, int RedTempId, int type)
{
try
{
RedemptionTemplateBO RedTemp = new RedemptionTemplateBO();
RedTemp = BlObj.GetRedemptionTemplateForEdit(RedTempId);
Hashtable TempStrings = new Hashtable();
if (type == 1)
{
TempStrings = GenerateRedemptionHashTable(id);
}
else if (type == 2)
{
TempStrings = GenerateRedemptionHashTableGift(id);
}
StringBuilder builder = new StringBuilder();
builder.Append("<html><head><title>Redemption Letter</title></head><body><style> @font-face {font-family: myFirstFont;src: url(~/fonts/Roboto-Regular.ttf);} p{font-family: 'Roboto', sans-serif;color: #3e3e3e;font-size: 15px;font-weight: 400;margin-bottom: 10px}</style>");
builder.Append(RedTemp.TemplateContent);
builder.Append("</body></html>");
foreach (string key in TempStrings.Keys)
{
builder.Replace("[" + key + "]", (string)TempStrings[key]);
}
return Content(builder.ToString());
}
catch( Exception ex)
{
throw new Exception("Return Template", ex);
}
}我已经使用一个断点签入了本地,如果我在字符串中获得了正确的数据,以便在第二个方法中返回。一切都好了。
它在本地和开发服务器上都运行良好。我得到了预期的pdf。
但当我在生产中运行的时候。我遇到了一个错误,它似乎没有击中尝试接球块。
“/”应用程序中的服务器错误。错误:加载页 http://app.com/Redemption/ReturnTemplate/185?RedTempId=3&type=2 失败(有时只需--加载错误处理忽略)退出,代码1由于网络错误而退出: RemoteHostClosedError描述:在执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以获得有关错误的更多信息,以及它起源于代码的位置。异常详细信息: System.Exception: Error:未能加载页面 http://app.com/Redemption/ReturnTemplate/185?RedTempId=3&type=2 (有时只需--加载-错误处理-忽略)退出代码1,因为网络错误: RemoteHostClosedError
这是最后几个堆栈跟踪
Rotativa.Core.WkhtmltopdfDriver.Convert(DriverOptions options, String html) +793
Rotativa.MVC.AsPdfResultBase.CallTheDriver(ControllerContext context) +27
Rotativa.MVC.AsPdfResultBase.BuildPdf(ControllerContext context) +203
Rotativa.MVC.AsPdfResultBase.ExecuteResult(ControllerContext context) +27WkhtmltopdfDriver需要很长时间才能从生产服务器响应。
这可能是由于罗塔蒂瓦服务器中的一些传出电话。但是,我的其他pdf代在生产服务器中使用rotativa仍然很好。
发布于 2020-04-04 13:09:31
我们有一个类似但不同的错误:Failed loading page:...HostNotFoundError
基本上,rotativa试图从内部网中解析域名,但是这个特定的网络不允许您使用其绑定的域名访问自己的面向公共的站点。切换到.UrlAsAPdf并使用intranet IP地址,对此进行了修复。
另外,首先在本地测试PDF视图/页面,看看它是否在做您想做的事情。
https://stackoverflow.com/questions/46275810
复制相似问题