【问题标题】:Include html page in aspx - Strange outcome with Response.WriteFile()在 aspx 中包含 html 页面 - 带有 Response.WriteFile() 的奇怪结果
【发布时间】:2025-12-05 09:30:02
【问题描述】:

我需要将相同的html 页面包含到几个aspx 页面中。以下是我的html 页面:

<h1>Database Enciclopedico</h1>

我使用Response.WriteFile 方法将该页面包含在我的aspx 页面中:

<div id="header">
        <% Response.WriteFile("Header.html"); %>
    </div>

问题是,当包含 html 页面时,它的开头有几个新行和空格(我可以在使用谷歌浏览器检查元素时看到结果)。

我该如何解决这个问题?

【问题讨论】:

    标签: c# html asp.net include


    【解决方案1】:

    像这样使用 HTML iframe:

        <iframe id='iframe1' name='iframe1' src='abc.html'>//also add attributes of height and width
    
    </iframe>
    

    【讨论】:

      【解决方案2】:

      请尝试以下方法:

      <%
          string path = HttpContext.Current.Server.MapPath("Header.html");
          string content = System.IO.File.ReadAllText(path);
          Response.Write(content);
      %>
      

      【讨论】:

        最近更新 更多