コード例 #1
0
        VPathToHost GetOrCreateApplication(string vhost, int port, string filepath, string virt)
        {
            VPathToHost   vapp       = null;
            string        vdir       = Path.GetDirectoryName(virt);
            string        pdir       = Path.GetDirectoryName(filepath);
            DirectoryInfo vinfo      = new DirectoryInfo(vdir);
            DirectoryInfo pinfo      = new DirectoryInfo(pdir);
            string        final_pdir = null;
            string        final_vdir = null;

            while (vinfo != null && pinfo != null)
            {
                if (final_pdir == null && 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();
            }


            //Console.Error.WriteLine ("final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir);
            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);
        }
コード例 #2
0
        void RunInternal(object state)
        {
            RequestData rdata = initial.RequestData;

            initial.FreeBuffer();
            string vhost = null;             // TODO: read the headers in InitialWorkerRequest
            int    port  = ((IPEndPoint)localEP).Port;

            VPathToHost        vapp = server.GetApplicationForPath(vhost, port, rdata.Path, true);
            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);

#if MONO
            if (ssl != null)
            {
                SslServerStream s = (stream as SslServerStream);
                ssl.KeySize       = s.CipherStrength;
                ssl.SecretKeySize = s.KeyExchangeStrength;
            }
#endif

            try {
                string redirect;
                vapp.Redirect(rdata.Path, out redirect);
                host.ProcessRequest(requestId, localEP.Address.Address, localEP.Port,
                                    remoteEP.Address.Address, remoteEP.Port, 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.
                Console.Error.WriteLine(fnf);
            } catch (IOException) {
                // This is ok (including EndOfStreamException)
            } catch (Exception e) {
                Console.Error.WriteLine(e);
            }
        }
コード例 #3
0
        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());
        }