gpt4 book ai didi

c# - 从文件系统读取 ASPX 文件并呈现为 HTML

转载 作者:太空狗 更新时间:2023-10-30 01:27:17 25 4
gpt4 key购买 nike

是否可以读取 aspx 文件并呈现为 html 文件,并将生成的 html 文件写入磁盘?

.aspx 文件在没有代码隐藏文件的文件系统上。如果可能,请提供一些示例代码。

最佳答案

来自远程 url

byte[] buf = new byte[8192];
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(path);
webRequest.KeepAlive = false;
string content = string.Empty;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
if (!(webResponse.StatusCode == HttpStatusCode.OK))
if (_log.IsErrorEnabled) _log.Error(string.Format("Url {0} not found", path));

Stream resStream = webResponse.GetResponseStream();

int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
content += encoding.GetString(buf, 0, count);
}
}
while (count > 0);

来自网络或虚拟路径

string content = string.Empty;
path = HttpContext.Current.Server.MapPath(path);

if (!File.Exists(path))
if (_log.IsErrorEnabled) _log.Error(string.Format("file {0} not found", path));

StreamReader sr = new StreamReader(path, encoding);
content = sr.ReadToEnd();

关于c# - 从文件系统读取 ASPX 文件并呈现为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com