コード例 #1
0
        //Will be called when an ASPX page is to be served.
        public void ProcessRequest(String page, string query, AspxRequestInfo dataHolder)
        {
            //catch the exception so we dont bring down the whole app

            try
            {
                if (string.IsNullOrEmpty(page))
                {
                    if (File.Exists(Path.Combine(m_PhysicalDirectory, "index.aspx")))
                    {
                        page = "index.aspx";
                    }
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "default.aspx")))
                    {
                        page = "default.aspx";
                    }
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "index.html")))
                    {
                        page = "index.html";
                    }
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "default.html")))
                    {
                        page = "default.html";
                    }
                }

                if (page != null && (page.ToLower().EndsWith("gif") || page.ToLower().EndsWith("jpg") || page.ToLower().EndsWith("png") || page.ToLower().EndsWith("html")) && File.Exists(Path.Combine(m_PhysicalDirectory, page)))
                {
                    var          _FileName     = Path.Combine(m_PhysicalDirectory, page);
                    FileStream   _FileStream   = new FileStream(_FileName, FileMode.Open, FileAccess.Read);
                    BinaryReader _BinaryReader = new BinaryReader(_FileStream);
                    long         _TotalBytes   = new FileInfo(_FileName).Length;
                    var          _Buffer       = _BinaryReader.ReadBytes((Int32)_TotalBytes);
                    _FileStream.Close();
                    _FileStream.Dispose();
                    _BinaryReader.Close();
                    dataHolder.ResponseStream.Write(_Buffer, 0, (int)_TotalBytes);
                }
                else
                {
                    AspxPage swr = new AspxPage(page, query, dataHolder);
                    HttpRuntime.ProcessRequest(swr);
                }
            }
            catch (Exception e1)
            {
                //Supress the internal exception. If needed we can pass the exception back
                dataHolder.ResponseStreamAsWriter.WriteLine("500 Internal Error.");
                throw new AspxException("Internal Error", e1);
            }
            finally
            {
                //Flush the response stream so that the Browser/calling application doesnt time out
                dataHolder.ResponseStreamAsWriter.Flush();
            }
        }
コード例 #2
0
        //Will be called when an ASPX page is to be served.
        public void ProcessRequest(String page, string query, AspxRequestInfo dataHolder)
        { 
            //catch the exception so we dont bring down the whole app

            try
            {
                if (string.IsNullOrEmpty(page))
                {
                    if (File.Exists(Path.Combine(m_PhysicalDirectory, "index.aspx")))
                        page = "index.aspx";
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "default.aspx")))
                        page = "default.aspx";
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "index.html")))
                        page = "index.html";
                    else if (File.Exists(Path.Combine(m_PhysicalDirectory, "default.html")))
                        page = "default.html";
                }

                if (page != null && (page.ToLower().EndsWith("gif") || page.ToLower().EndsWith("jpg") || page.ToLower().EndsWith("png") || page.ToLower().EndsWith("html")) && File.Exists(Path.Combine(m_PhysicalDirectory, page)))
                {
                    var _FileName = Path.Combine(m_PhysicalDirectory, page);
                    FileStream _FileStream = new FileStream(_FileName, FileMode.Open, FileAccess.Read);
                    BinaryReader _BinaryReader = new BinaryReader(_FileStream);
                    long _TotalBytes = new FileInfo(_FileName).Length;
                    var _Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
                    _FileStream.Close();
                    _FileStream.Dispose();
                    _BinaryReader.Close();                    
                    dataHolder.ResponseStream.Write(_Buffer, 0, (int)_TotalBytes);
                }
                else
                {
                    AspxPage swr = new AspxPage(page, query, dataHolder);
                    HttpRuntime.ProcessRequest(swr);
                }
            }
            catch (Exception e1)
            {
                //Supress the internal exception. If needed we can pass the exception back
                dataHolder.ResponseStreamAsWriter.WriteLine("500 Internal Error.");
                throw new AspxException("Internal Error", e1);
            }
            finally
            {
                //Flush the response stream so that the Browser/calling application doesnt time out
                dataHolder.ResponseStreamAsWriter.Flush();
            }
        }