是否可以读取aspx文件并呈现为html文件,并将生成的html文件写入磁盘?
.aspx文件位于没有codebehind文件的文件系统上.如果可能,请提供一些示例代码.
解决方法:
来自远程网址
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,asp-net,rendering
来源: https://codeday.me/bug/20190627/1299585.html