VPathToHost GetOrCreateApplication(string vhost, int port, string filepath, string virt) { string vdir = Path.GetDirectoryName(virt); string pdir = Path.GetDirectoryName(filepath); var vinfo = new DirectoryInfo(vdir); var pinfo = new DirectoryInfo(pdir); string final_pdir = null; string final_vdir = null; while (vinfo != null && pinfo != null) { if (CheckDirectory(pinfo)) { final_pdir = pinfo.ToString(); final_vdir = vinfo.ToString(); break; } if (pinfo.Name != vinfo.Name) { final_vdir = vinfo.ToString(); break; } pinfo = pinfo.Parent; vinfo = vinfo.Parent; } if (final_pdir == null) { final_pdir = pinfo.ToString(); } if (final_vdir == null) { final_vdir = vinfo.ToString(); } //Logger.Write (LogLevel.Error, "final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir); VPathToHost vapp = server.GetApplicationForPath(vhost, port, virt, false); if (vapp == null) { // Don't know why this breaks mod-mono-server2.exe, but not mod-mono-server.exe //final_pdir = "file://" + final_pdir; if (final_vdir [0] != '/') { final_vdir = "/" + final_vdir; } server.AddApplication(vhost, port, final_vdir, final_pdir); vapp = server.GetApplicationForPath(vhost, port, virt, false); } return(vapp); }
public static VPathToHost GetApplicationForPath(string vhost, int port, string path, string realPath) { return(appserver.GetApplicationForPath(vhost, port, path, false)); }
void RunInternal(object state) { RequestData rdata = initial.RequestData; initial.FreeBuffer(); string vhost = null; // TODO: read the headers in InitialWorkerRequest int port = localEP.Port; VPathToHost vapp; try { vapp = server.GetApplicationForPath(vhost, port, rdata.Path, true); } catch (Exception e) { // // This happens if the assembly is not in the GAC, so we report this // error here. // Logger.Write(e); return; } XSPApplicationHost host = null; if (vapp != null) { host = (XSPApplicationHost)vapp.AppHost; } if (host == null) { byte [] nf = HttpErrors.NotFound(rdata.Path); Write(nf, 0, nf.Length); Close(); return; } broker = (XSPRequestBroker)vapp.RequestBroker; requestId = broker.RegisterRequest(this); try { string redirect; vapp.Redirect(rdata.Path, out redirect); host.ProcessRequest(requestId, localEP, remoteEP, rdata.Verb, rdata.Path, rdata.QueryString, rdata.Protocol, rdata.InputBuffer, redirect, sock.Handle, ssl); } catch (FileNotFoundException fnf) { // We print this one, as it might be a sign of a bad deployment // once we require the .exe and Mono.WebServer in bin or the GAC. Logger.Write(fnf); } catch (IOException) { // This is ok (including EndOfStreamException) } catch (Exception e) { Logger.Write(e); } }
VPathToHost GetOrCreateApplication(string vhost, int port, string filepath, string virt) { string final_vdir; string final_pdir; GetPhysicalDirectory(virt, filepath, out final_vdir, out final_pdir); //Logger.Write (LogLevel.Error, "final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir); VPathToHost vapp = server.GetApplicationForPath(vhost, port, virt, false); if (vapp == null) { // Don't know why this breaks mod-mono-server2.exe, but not mod-mono-server.exe //final_pdir = "file://" + final_pdir; if (final_vdir [0] != '/') { final_vdir = "/" + final_vdir; } server.AddApplication(vhost, port, final_vdir, final_pdir); vapp = server.GetApplicationForPath(vhost, port, virt, false); } return(vapp); }
public static void Start() { XSPWebSource websource = new XSPWebSource(IPAddress.Loopback, 0); WebAppServer = new ApplicationServer(websource); string basePath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString(); string serverPath = basePath; if (serverPath[serverPath.Length - 1] != System.IO.Path.DirectorySeparatorChar) { serverPath += System.IO.Path.DirectorySeparatorChar; } serverPath += "WebUI"; string serverBinPath = serverPath + System.IO.Path.DirectorySeparatorChar + "bin" + System.IO.Path.DirectorySeparatorChar; WebAppServer.AddApplication("", -1, "/", serverPath); bool started = false; DateTime curr = DateTime.Now; while (!started && curr.AddMinutes(1) > DateTime.Now) { try { WebAppServer.Start(true); started = true; } catch (System.Net.Sockets.SocketException e) { if (e.ErrorCode == 10049 || e.ErrorCode == 10022) { //strange error on bind, probably network still not started //try to rerun server System.Threading.Thread.Sleep(10000); //WebAppServer.Start(true); } else { throw; } } } if (!started) { WebAppServer.Start(true); } //copy Mono.WebServer2.dll /*try * { * if (!Directory.Exists(serverBinPath)) * Directory.CreateDirectory(serverBinPath); * * File.Copy(basePath + System.IO.Path.DirectorySeparatorChar+"Mono.WebServer2.dll", serverBinPath + "Mono.WebServer2.dll", true); * } * * catch { ;} */ AppDomain ap = WebAppServer.GetApplicationForPath("", WebAppServer.Port, "/", false).AppHost.Domain; ap.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); ap.UnhandledException += OnUnhandledExceptionEvent; ap.SetData("WebUIGate", webServerGate); port = WebAppServer.Port; //uri = new Uri("http://127.0.0.1:" + port.ToString() + "/"); uri = new Uri("http://localhost:" + port.ToString() + "/"); Console.WriteLine("Webserver started at " + uri.ToString()); }