Compile ASPX in WinForms App

一个人想着一个人 提交于 2020-01-02 05:34:11

问题


I'm writing a WinForms application that sends email messages (like a mail merge).

I'd like to use ASP.Net's rendering engine to render the HTML bodies of the messages.

What's the simplest way to get the rendered output of a single ASPX page without the entire ASP.Net runtime?

To make things harder, I'd prefer to compile the ASPX at runtime so that it can be modified without rebuilding the application. However, this is not a requirement; if it's too difficult, I'll give up on it.


回答1:


Rick Strahl posted an article how to do this at this location: http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp. I know there is a way to call some internal .NET Framework methods but I can't remember what they are off hand.




回答2:


You may want to consider using a templating lib like NVelocity. Using the WebForms rendering engine in this manner is a bit overkill and hackish at best.

As an aside: keep in mind that HTML in email sucks. Even the most elementary of CSS is ignored by the majority of email clients. If you want my advice, KISS and save your sanity: if you're going to automate emails, send only plain text.



来源:https://stackoverflow.com/questions/1641304/compile-aspx-in-winforms-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!