code_junkie

How can I programmatically run the ASP.Net Development Server using C#?

Nov 10th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. C:WindowsMicrosoft.NETFrameworkv2.0.50727Webdev.WebServer.exe /port:[PORT NUMBER] /path: [PATH TO ROOT]
  2.  
  3. using System;
  4. using System.Diagnostics;
  5. using System.Web;
  6. ...
  7.  
  8. // settings
  9. string PortNumber = "1162"; // arbitrary unused port #
  10. string LocalHostUrl = string.Format("http://localhost:{0}", PortNumber);
  11. string PhysicalPath = Environment.CurrentDirectory // the path of compiled web app
  12. string VirtualPath = "";
  13. string RootUrl = LocalHostUrl + VirtualPath;
  14.  
  15. // create a new process to start the ASP.NET Development Server
  16. Process process = new Process();
  17.  
  18. /// configure the web server
  19. process.StartInfo.FileName = HttpRuntime.ClrInstallDirectory + "WebDev.WebServer.exe";
  20. process.StartInfo.Arguments = string.Format("/port:{0} /path:"{1}" /virtual:"{2}"", PortNumber, PhysicalPath, VirtualPath);
  21. process.StartInfo.CreateNoWindow = true;
  22. process.StartInfo.UseShellExecute = false;
  23.  
  24. // start the web server
  25. process.Start();
  26.  
  27. // rest of code...
Add Comment
Please, Sign In to add comment