ASP.NET 写出 HTML 文件的内容?

发布于 2024-10-09 02:11:10 字数 105 浏览 0 评论 0原文

我不知道这是否是一个愚蠢的问题,但是..

是否可以在 ASP.NET(C# 或 VB#)中使用 Response.Write() 另一个 HTML 文件的内容?如果是这样,怎么办?

I don't know if this is a stupid question but..

Is it possible in either ASP.NET (either C# or VB#) to Response.Write() the contents of another HTML file? If so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绿光 2024-10-16 02:11:10

逐行读取 HTML 文件并使用 Response.Write() 写入

 StreamReader sr = new StreamReader(@"C:\abc.html");
        while(sr.Peek() >= 0)
        {
           line=sr.ReadLine();
           Response.Write(line);

        }

Read the HTML file line by line and write it using Response.Write()

 StreamReader sr = new StreamReader(@"C:\abc.html");
        while(sr.Peek() >= 0)
        {
           line=sr.ReadLine();
           Response.Write(line);

        }
葬シ愛 2024-10-16 02:11:10

您可以将所有行放入字符串数组中并直接发送出去。

string[] lines = File.ReadAllLines("path/to/my/file.html");
foreach(string line in lines)
{
    Response.Write(line);
}

只是不要忘记正确设置标头,因为这只会注入 HTML。它不会设置任何可能预期的特殊标头(如果有)。

You can get all the lines into a string array and send them out directly.

string[] lines = File.ReadAllLines("path/to/my/file.html");
foreach(string line in lines)
{
    Response.Write(line);
}

Just don't forget to set your headers up correctly because this will just inject HTML. It won't set up any special headers that might be expected (if any).

夏花。依旧 2024-10-16 02:11:10

我知道这是一个老问题,但我对未来的研究有另一个解决方案。只使用 TrasmitFile 怎么样? IE:

Response.WriteFile(@"folder/filename.html");

I know this is an old question, but I have another solution for future researching. How about just use TrasmitFile? i.e.:

Response.WriteFile(@"folder/filename.html");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文