2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 动态生成静态网页

动态生成静态网页

时间:2024-03-09 05:15:21

相关推荐

动态生成静态网页

public void MakeHtml(){try{//动态页面网址string strUrl = "/product/Detail/Default.aspx?ContentID=123";//要存放静态网页的路径string filePath = "/product/";//物理完整路径string toFileFullPath = HttpContext.Current.Server.MapPath(filePath);//检查是否有该路径没有就创建if (!System.IO.Directory.Exists(toFileFullPath)){System.IO.Directory.CreateDirectory(toFileFullPath);}filePath = filePath + "index.html";if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(filePath))){File.Delete(System.Web.HttpContext.Current.Server.MapPath(filePath));}//创建请求//如果访问的地址是带证书的https,需要加上这句话,证书认证ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;HttpWebRequest Dd_gUrl = (HttpWebRequest)WebRequest.Create(strUrl);Dd_gUrl.UseDefaultCredentials = false;HttpWebResponse WebRe = (HttpWebResponse)Dd_gUrl.GetResponse();Stream strhtml = WebRe.GetResponseStream();StreamReader stRCmcnHtml = new StreamReader(strhtml, Encoding.GetEncoding("utf-8"));StreamWriter Sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(filePath), true, Encoding.GetEncoding("utf-8")); ;Sw.Write("<meta charset='utf-8'/>" + stRCmcnHtml.ReadToEnd());//<meta charset="utf-8"/>百度收录不乱码Sw.Flush();Sw.Close();strhtml.Close();WebRe.Close();stRCmcnHtml.Close();//return true;}catch (Exception ex){throw ex;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。