我正在尝试在另一个页面中执行ASP.Net剃刀网页,目的是使用电子邮件正文中返回的字符串(因此我可以在电子邮件中包含动态数据)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
@{ string response = "";
var sw = new StringWriter();
Server.Execute("~/WebPage.cshtml", sw, false);
response = sw.ToString();
}
<p>@response</p>
</body>
</html>
页面返回
Error executing child request for /WebPage.cshtml.
堆栈跟踪
[HttpException (0x80004005): Error executing child request for /WebPage.cshtml.]
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2684
System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm) +1273
ASP._Page_RazorSamplePage_cshtml.Execute() in \\***\*******\********\RazorSamplePage.cshtml:17
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.WebPages.WebPage.ExecutePageHierarchy() +360
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +110
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +218
WebPage.cshtml可以在浏览器中处理得很好,所以我不知道问题是什么。它是服务器上的信任设置吗?
子页面(WebPage.cshtml)代码在
之下<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>@DateTime.Now</p>
</body>
</html>