Dynamic Request page generate static page, request page static
Baidu also improves browsing speed in this way. In this case, the control is developed. MVC or common processing program development partners can be used in the same way as repair, modification, and modification;
Background:
1 protected void btnHtml_Click (object sender, EventArgs e) 2 {3 if (Request. QueryString ["id"]! = Null) 4 {5 string NewId = Request. queryString ["id"]; 6 CJRZ. model. admin. loanStrategy modeStrategy = bllNews. getModel (int. parse (NewId); 7 if (modeStrategy! = Null) 8 {9 CreatHtml cHtml = new CreatHtml (); 10 string url = "http: //" + HttpContext. current. request. url. host. toString () + ":" + HttpContext. current. request. url. port; 11 string AUrl = url + "/raiders/raiders_article.aspx? Id = "+ modeStrategy. newID; 12 // html page file name 13 string fna = Server. mapPath ("\") + "raiders \" + modeStrategy. newTypeID + "\"; 14 string FileName = modeStrategy. newID + ". html "; 15 if (cHtml. createList (AUrl, fna, FileName) 16 {17 modeStrategy. htmlUrl = url + "/raiders/" + modeStrategy. newTypeID + "/" + FileName; 18 hlkLook. navigateUrl = modeStrategy. htmlUrl; 19 if (bllNews. update (modeStrategy) 20 {21 Mess AgeBox. Show (this, "file generated successfully"); 22} 23 else24 {25 MessageBox. Show (this, "An error occurred while updating the data path! "); 26} 27} 28 else29 {30 MessageBox. Show (this," An error occurred while generating the file! "); 31} 32} 33 else34 {35 MessageBox. Show (this," An error occurred while obtaining the news object! "); 36} 37 38} 39 else40 {41 MessageBox. Show (this," An error occurred while obtaining the ID number! "); 42} 43}
Front-end:
1 <asp: Button ID = "btnHtml" runat = "server" Text = "generate static page" onclick = "btnHtml_Click" Visible = "false"/> 2 & nbsp; & nbsp; 3 <asp: hyperLink ID = "hlkLook" runat = "server" style = "color: Blue; font-size: 14px;" Target = "_ blank"> View page </asp: HyperLink>
Called class:
1 public class CreatHtml 2 {3 public bool CreateList (string url, string fna, string fileName) 4 {5 bool OK; 6 // prepare to generate 7 string strHtml; 8 StreamReader sr = null; // used to read stream 9 StreamWriter sw = null; // used to write file 10 Encoding code = Encoding. getEncoding ("UTF-8"); // defines the encoding 11 12 // construct a web request, send the request, and obtain the response 13 WebRequest HttpWebRequest = null; 14 WebResponse HttpWebResponse = null; 15 HttpWebRequest = WebRequest. create (url ); 16 HttpWebResponse = HttpWebRequest. getResponse (); 17 18 // get stream 19 sr = new StreamReader (HttpWebResponse. getResponseStream (), code); 20 strHtml = sr. readToEnd (); 21 22 // Write File 23 try24 {25 26 if (! Directory. exists (fna) 27 {28 Directory. createDirectory (fna); 29} 30 sw = new StreamWriter (fna + "\" + fileName, false, code); 31 sw. writeLine (strHtml); 32 sw. flush (); 33 OK = true; 34} 35 catch (Exception ex) 36 {37 OK = false; 38} 39 finally40 {41 if (sw! = Null) 42 {43 sw. Close (); 44} 45} 46 return OK; 47} 48}