MVC 内容转为html页面
public bool ExecMVCToHtml() { string url = aspxUrl; if (url.IndexOf("/") != 0) url = "/" + url; string address = Framework.Utils.RootURL + url; StreamWriter sw = new StreamWriter(htmlSavePath, false, encoder); try { string strResult = Utils.GetWebRequest(address, encoder); if (!string.IsNullOrEmpty(strResult)) { sw.Write(strResult); //将strHTML中的字符写到.html中 sw.Flush(); return true; } else return false; } catch { return false; } finally { sw.Close(); //关闭StreamWriter } }
/// <summary> /// 通过HttpWebRequest获取结果 /// </summary> public static string GetWebRequest(string url, Encoding encoder) { Stream myStream = null; StreamReader sr = null; try { HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse(); myStream = HttpWResp.GetResponseStream(); sr = new StreamReader(myStream, encoder); return sr.ReadToEnd(); } catch (Exception e) { return e.Message; } finally { if (sr != null) sr.Close(); if (myStream != null) myStream.Close(); } }
111111