Program1.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Web.UI;
  3. using System.Web;
  4. using System.Web.Hosting;
  5. using ClassLibrary1;
  6. using System.IO;
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main (string[] args)
  12. {
  13. string master = @"<%@ Master Language=""C#"" %>
  14. <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
  15. <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" >
  16. <head id=""Head1"" runat=""server"">
  17. <title></title>
  18. </head>
  19. <body>
  20. <asp:contentplaceholder id=""Main"" runat=""server"" />
  21. </body>
  22. </html>";
  23. string page = @"<%@ Page MasterPageFile=""My.master"" %>
  24. <asp:content id=""Content1"" contentplaceholderid=""Main"" runat=""server"">
  25. <form id=""form1"" runat=""server"" />
  26. </asp:content>";
  27. string physDir = Directory.GetCurrentDirectory ();
  28. if (!Directory.Exists ("bin"))
  29. Directory.CreateDirectory ("bin");
  30. string masterPath = "My.master";
  31. if (!File.Exists (masterPath))
  32. using (StreamWriter sw = new StreamWriter (masterPath))
  33. sw.Write (master);
  34. string pagePath = "PageWithMaster.aspx";
  35. if (!File.Exists (pagePath))
  36. using (StreamWriter sw = new StreamWriter (pagePath))
  37. sw.Write (page);
  38. Class1 c1 = (Class1) ApplicationHost.CreateApplicationHost (
  39. typeof (Class1), "/", physDir);
  40. c1.Run ();
  41. }
  42. }
  43. }