Example #1
0
        private void Init()
        {
            System.Xml.XmlDocument _document = new System.Xml.XmlDocument();
            _document.Load(Xy.Tools.IO.File.foundConfigurationFile("UrlControl", Xy.AppSetting.FILE_EXT));
            System.Xml.XmlNodeList default_xnl = _document.SelectNodes("UrlRewrite/Item");

            _defaultUrlControl = new URLCollection(string.Empty, string.Empty, string.Empty, string.Empty);
            foreach (System.Xml.XmlNode _xn in default_xnl)
            {
                _defaultUrlControl.Add(new URLItem(_xn));
            }

            _defaultUrlControl.Add(new URLItem(null, null, @".*\.js$", "application/x-javascript", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.css$", "text/css", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.gif$", "image/gif", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.jpg$", "image/jpeg", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.png$", "image/png", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.bmp$", "image/bmp", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.swf$", "application/x-shockwave-flash", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @".*\.ico$", "image/x-icon", false, false, "ResourceFile", URLItem.DEFAULTAGE));
            _defaultUrlControl.Add(new URLItem(null, null, @"^/Xy_(App|Data|Log)/.*", "text/html", false, false, "Prohibit", 0));
            _defaultUrlControl.Add(new URLItem(null, null, @"^/Xy_Theme/[^/]+/Xy_(Cache|Include|Page|Xslt)/.*", "text/html", false, false, "Prohibit", 0));
            _defaultUrlControl.Add(new URLItem(null, "Xy.Web,Xy.Web.Page.ErrorPage", @"^/error\.aspx", "text/html", true, false, "MainContent", 0));

            _urlControl = new List <URLCollection>();
            foreach (System.Xml.XmlElement _xe in _document.SelectNodes("UrlRewrite/UrlCollection"))
            {
                URLCollection _urlItemCollection = new URLCollection(_xe);
                if (_urlItemCollection.SiteUrlReg == null && string.IsNullOrEmpty(_urlItemCollection.Name))
                {
                    continue;
                }

                foreach (System.Xml.XmlNode _xn in _xe.SelectNodes("Item"))
                {
                    _urlItemCollection.Add(new URLItem(_xn));
                }
                URLCollection _parent = null;
                if (!string.IsNullOrEmpty(_urlItemCollection.Inherit))
                {
                    _parent = GetUrlItemCollection(_urlItemCollection.Inherit);
                }
                if (_parent == null)
                {
                    _parent = _defaultUrlControl;
                }
                _urlItemCollection.AddRange(_parent.ToArray());
                _urlControl.Add(_urlItemCollection);
            }
        }
Example #2
0
 internal URLCollection GetUrlItemCollection(Xy.Tools.Web.UrlAnalyzer regUrl)
 {
     if (_urlControl == null)
     {
         Init();
     }
     for (int i = 0; i < _urlControl.Count; i++)
     {
         if (_urlControl[i].IsMatch(regUrl.Site))
         {
             URLCollection _current = _urlControl[i];
             if (!string.IsNullOrEmpty(_current.WebConfig.Root))
             {
                 if (!regUrl.HasRoot(_current.WebConfig.Root))
                 {
                     continue;
                 }
             }
             return(_current);
         }
     }
     return(null);
 }
Example #3
0
        private void context_BeginRequest(object sender, EventArgs e)
        {
            global.RequestStart(sender, e);
            HttpApplication _application = sender as HttpApplication;

#if DEBUG
            Xy.Tools.Debug.Log.StartWorkflowLog();
            Xy.Tools.Debug.Log.WriteEventLog("start " + _application.Context.Request.Url.ToString());
#endif
            Xy.Tools.Web.UrlAnalyzer _url = new Tools.Web.UrlAnalyzer(_application.Context.Request.Url.ToString());

            URLManage.URLCollection _urlCollection = _urlManager.GetUrlItemCollection(_url);
            if (_urlCollection == null)
            {
                throw new Exception(string.Format("can not found URL collection: {0}", _url.ToString()));
            }
            else
            {
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("get url collection.");
#endif
                Xy.WebSetting.WebSettingItem _webSetting = _urlCollection.WebConfig;
                if (!string.IsNullOrEmpty(_webSetting.Root))
                {
                    _url.SetRoot(_webSetting.Root);
                }
                if (!string.IsNullOrEmpty(_webSetting.Port))
                {
                    _url.SetPort(_webSetting.Port);
                }
#if DEBUG
                Xy.Tools.Debug.Log.WriteEventLog("get websetting item.");
#endif
                URLManage.URLItem _urlItem = _urlCollection.GetUrlItem(_url.Path);
                if (_urlItem == null)
                {
                    if (!_webSetting.Compatible)
                    {
                        throw new Exception(string.Format("can not found URL item: {0}", _url.ToString()));
                    }
                }
                else
                {
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("get url item.");
#endif
                    ThreadEntity _entity = new ThreadEntity(_application.Context, _webSetting, _urlItem, _url);
                    global.HandleStart(_entity);
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("created thread entity");
#endif
                    _entity.Handle();
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("thread entity handled");
#endif
                    if (_entity.Content.HasContent)
                    {
                        _application.Response.BinaryWrite(_entity.Content.ToArray());
                    }
                    global.HandleEnd(_entity);
#if DEBUG
                    Xy.Tools.Debug.Log.WriteEventLog("content outputed");
                    Xy.Tools.Debug.Log.EndWorkflowLog();
#endif
                    _application.Context.Response.End();
                }
            }
        }
Example #4
0
        private void context_Error(object sender, EventArgs e)
        {
            HttpApplication _application = sender as HttpApplication;
            Exception       exception    = _application.Context.Server.GetLastError();

            _application.Context.Server.ClearError();
            Xy.WebSetting.WebSettingItem _webSetting = null;
            try {
                Xy.Tools.Web.UrlAnalyzer _url           = new Xy.Tools.Web.UrlAnalyzer(_application.Context.Request.Url.ToString());
                URLManage.URLCollection  _urlCollection = URLManage.URLManager.GetInstance().GetUrlItemCollection(_url);
                if (_urlCollection != null)
                {
                    URLManage.URLItem _urlItem  = null;
                    string            _errorURL = _url.Dir.TrimEnd('/');
                    do
                    {
                        _urlItem = _urlCollection.GetUrlItem(_errorURL + "/error.aspx");
                        if (_urlItem != null)
                        {
                            break;
                        }
                        _errorURL = _errorURL.Substring(0, Math.Max(0, _errorURL.LastIndexOf('/')));
                    } while (_errorURL.Length > 0);
                    if (_urlItem != null)
                    {
                        if (_urlItem.ContentType != URLManage.URLType.Prohibit)
                        {
                            _webSetting = Xy.WebSetting.WebSettingCollection.GetWebSetting(_urlCollection.WebConfigName);
                            ThreadEntity _entity = new ThreadEntity(_application.Context, _webSetting, _urlItem, _url);
                            //_entity.Handle();
                            _application.Response.ContentType = _urlItem.Mime;
                            Xy.Web.Page.ErrorPage _errpage = Runtime.Web.PageClassLibrary.Get(_urlItem.PageClassName) as Xy.Web.Page.ErrorPage;
                            if (_errpage != null)
                            {
                                _errpage.setError(exception);
                                _errpage.Init(_entity, _webSetting);
                                _errpage.Handle("@PageDir:" + _urlItem.PagePath, _urlItem.PagePath, _urlItem.EnableScript, false);
                                if (_errpage.HTMLContainer.HasContent)
                                {
                                    _application.Response.BinaryWrite(_errpage.HTMLContainer.ToArray());
                                    _application.Context.Response.End();
                                    return;
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                exception = new Exception("Error page class exception:" + ex.Message, exception);
            }
            StringBuilder errorsb = new StringBuilder();

            errorsb.AppendLine(@"<!DOCTYPE HTML><html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /><title>Error Page</title></head><body>");
            errorsb.AppendLine("<strong>Wrong Time:</strong>" + DateTime.Now.ToString());
            errorsb.AppendLine("<strong>Client IP:</strong>" + _application.Context.Request.UserHostAddress);
            errorsb.AppendLine("<strong>Browser:</strong>" + _application.Context.Request.Browser.Browser);
            errorsb.AppendLine("<strong>Offending URL:</strong> " + _application.Request.Url.ToString());
            Exception inex = exception;
            int       i    = 1;

            while (inex != null)
            {
                errorsb.AppendLine("=============================Exception No." + i + ": " + inex.Message.Replace(Environment.NewLine, string.Empty) + "=============================");
                if (_webSetting != null && _webSetting.DebugMode)
                {
                    errorsb.AppendLine("<strong>Source: </strong>" + inex.Source);
                    if (inex.TargetSite != null)
                    {
                        errorsb.AppendLine("<strong>TargetMethod: </strong>" + inex.TargetSite.ToString());
                    }
                    errorsb.AppendLine("<strong>Data: </strong>" + inex.Data.ToString());
                    errorsb.AppendLine("<strong>StackTrace: </strong>" + inex.StackTrace);
                    errorsb.AppendLine();
                }
                inex = inex.InnerException; i++;
            }
            errorsb.Append(@"</body></html>");
            _application.Context.Response.BinaryWrite(_application.Context.Request.ContentEncoding.GetBytes(errorsb.ToString().Replace(Environment.NewLine, "<br />" + Environment.NewLine)));
            _application.Context.Response.End();
        }