C#动态生成HTML [英] C# Dynamicly Generating HTML
问题描述
大家好,
我有一个与多个客户端通信的Server App.
我需要将字符串形式的html页面发送给客户端,并且我可以做到.
html页面需要即时生成,并且必须包含帐户信息.
我需要能够在不停止服务器的情况下动态更改生成的内容.
因此,我正在考虑拥有一个XML文件,其中包含需要从SQL数据库中获取的字段",然后才在服务器中读取xml文件并生成内容.
我的逻辑在这里是正确的,还是有更好的方法呢?
Hey Guys,
I have a Server App that communicates with multiple clients.
I need to send the client an html page as a string, and that I can do.
The html page needs to be generated on the fly, and it must contain account info.
I need to be able to change the generated content dynamically without stopping the server.
So I''m thinking about having a XML file that contains the "fields" I need to fetch from a SQL db, and then just then read the xml file in the server and generate the content.
Is my logic correct here, or is there a better way to do it?
How would I go about doing it?
推荐答案
如果html几乎是静态的,只插入了一些数据值,我建议将html文件另存为您的应用程序项目,在数据需要放置的地方放置诸如"[replaceThisWithxxx]"之类的标签.然后,您无需立即创建html,而只需将整个文件内容加载到字符串中,然后使用适当的数据替换标签即可.
If the html is pretty much static with just some data values inserted, I would suggest saving the html file as a file in your application project, placing tags like "[replaceThisWithxxx]" where the data needs to go. Then, instead of creating html on the fly, you can just load the entire file contents into a string and perform a replace on the tags with the appropriate data.
Response.Write("<div><font size='2' face='Tahoma'><B>" +
mydata + "</B></font></div>");
Response.Write("<div style=''position:absolute; background-color:#D1FFFF ; width:150px; height:150px;''>");
这篇关于C#动态生成HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!