简体   繁体   English

如何在ASP.NET Webform中显示HTML文件

[英]How to display HTML file inside ASP.NET Webform

I have an embed device which is returning back info in HTML files, Now I trying to make ASP.NET webform application, so end users can see these logs.我有一个嵌入设备,它返回 HTML 文件中的信息,现在我尝试制作 ASP.NET webform 应用程序,以便最终用户可以看到这些日志。 What is proper way to open HTML file at local server and display inside webform.在本地服务器上打开 HTML 文件并显示在 webform 中的正确方法是什么。

If they are complete HTML files (including <html> and <body> tags) then it's probably best to show them in a Frame. 如果它们是完整的HTML文件(包括<html><body>标记),则最好将它们显示在Frame中。 Are they in a location you can create an URL for? 它们是否在您可以为其创建URL的位置?

For html fragments you'll have to load them in code-behind and show them in for example a Literal control. 对于html片段,您必须将其加载到后台代码中,并在例如Literal控件中显示它们。

您可以使用HttpUtility.HtmlEncode(CONTENTSOFHTMLFILE)并将其输出到labelliteral控件

in aspx file:aspx文件中:

<asp:Literal runat="server" ID="htmlLiteral" />

in cs file Page_Load method:在 cs 文件中Page_Load方法:

htmlLiteral.Text = "<h2>aaa</h2>";

Replace aaa h2 with your complete html string将 aaa h2 替换为完整的 html 字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM