将 MVC3 操作从 WCF REST 服务方法呈现为字符串
我有一个 WCF REST 服务,它接受一些参数并发送电子邮件。电子邮件的模板是 MVC3 操作。本质上我想将该操作呈现为字符串。
如果它是 ASP.NET WebForm,我可以简单地使用 Server.Execute(path, stringWriter, false)。但是,当我插入操作的路径时,我收到执行子请求时出错
。
我可以从我的服务 (AspNetCompatibilityRequirementsMode.Allowed
) 完全访问 HttpContext。
我知道还有其他答案可以从控制器的上下文中将操作呈现给字符串。当我不在那个世界但仍在同一服务器上(并且就此而言,在同一个应用程序中)时,我该如何执行此操作?
I have a WCF REST service that takes some parameters and sends an email. The template for the email is an MVC3 action. Essentially I want to render that action to a string.
If it were an ASP.NET WebForm, I could simply use Server.Execute(path, stringWriter, false)
. However when I plug in the path to my action, I get Error executing child request
.
I have full access to HttpContext from my service (AspNetCompatibilityRequirementsMode.Allowed
).
I know there are other answers out there for rendering actions to strings from within the context of a controller. How do I do this when I'm outside that world, but still on the same server (and, for that matter, in the same app)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我根据几个不同的谷歌搜索拼凑了一个答案。它有效,但我不能 100% 确定它是否尽可能精简。我将代码粘贴给其他人尝试。
I cobbled together an answer based on several different google searches. It works, but I'm not 100% sure it's as lean as it could be. I'll paste the code for others to try.