public ThreadEntity(System.Web.HttpContext webApp, WebSetting.WebSettingItem webSetting, URLManage.URLItem urlItem, Xy.Tools.Web.UrlAnalyzer currentURL) { _webContext = webApp; _webSetting = webSetting; _urlItem = urlItem; _url = currentURL; _content = new HTMLContainer(_webSetting.Encoding); }
public void Init(ThreadEntity threadEntity, WebSetting.WebSettingItem webSetting) { _threadEntity = threadEntity; _htmlContainer = new HTMLContainer(_threadEntity.WebSetting.Encoding); _server = _threadEntity.WebContext.Server; _url = threadEntity.URL; _updateLocalCache = false; _response = new PageResponse(_threadEntity, _htmlContainer); _request = new PageRequest(_threadEntity); _pageData = new PageData(); _pageSession = PageSessionCollection.GetInstance().GetSession(_threadEntity); _webSetting = webSetting; }
public void Init(PageAbstract page, WebSetting.WebSettingItem webSetting, HTMLContainer container) { _threadEntity = page._threadEntity; _server = page._server; _updateLocalCache = page._updateLocalCache; _request = page._request; _pageData = page._pageData; _pageSession = page._pageSession; _url = page._url; _webSetting = webSetting; _response = page._response; _response.SetNewContainer(container); _htmlContainer = container; }
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); }
public void Handle(ThreadEntity CurrentThreadEntity, Page.PageAbstract CurrentPageClass) { _threadEntity = CurrentThreadEntity; _innerHTML.Clear(); _threadEntity.ControlIndex++; Xy.Tools.Web.UrlAnalyzer _url = CurrentThreadEntity.URL; if (_webSetting == null) { _webSetting = CurrentPageClass.WebSetting; } if (_webSetting.AutoUrl) { _webSetting.UpdateDomain(CurrentThreadEntity.URL.Site); } URLManage.URLItem _urlItem = new URLManage.URLItem(_file, _type, _threadEntity.URLItem.Regex.ToString(), _threadEntity.URLItem.Mime, _enableScript, _enableCache, _threadEntity.URLItem.ContentType.ToString(), _threadEntity.URLItem.Age.Minutes); ThreadEntity _entity = new ThreadEntity(CurrentThreadEntity.WebContext, _webSetting, _urlItem, _url, true); _entity.Handle(_extValues); if (_entity.Content.HasContent) { _innerHTML.Write(_entity.Content); } _threadEntity.ControlIndex--; }
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(); }
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(); }
public static void ClearCache(string PageID, string ControlID, Xy.WebSetting.WebSettingItem websetting, Xy.Tools.Web.UrlAnalyzer url, bool cacheUrlParam = true) { ClearCache(GetCacheFilePath(PageID, ControlID, websetting, url, cacheUrlParam)); }
public static string GetCacheFilePath(string PageID, string ControlID, Xy.WebSetting.WebSettingItem websetting, Xy.Tools.Web.UrlAnalyzer url, bool cacheUrlParam = false) { StringBuilder _sb = new StringBuilder(); _sb.Append(websetting.CacheDir); _sb.Append(url.Path.Replace('/', '\\')); if (cacheUrlParam) { _sb.Append(url.Param.Replace('?', '#')); } //_sb.Append('#'); //int index = 0; //int inindex = 0; //int temp = 0; //foreach (System.Text.RegularExpressions.Group itemGroup in urlitem.Regex.Match(url.Path).Groups) { // string tempName = urlitem.Regex.GroupNameFromNumber(index++); // if (!int.TryParse(tempName, out temp)) { // if (inindex++ != 0) _sb.Append('&'); // _sb.Append(tempName); // _sb.Append('='); // _sb.Append(itemGroup.Value); // } //} if (!string.IsNullOrEmpty(PageID)) { _sb.Append("-" + PageID); } if (!string.IsNullOrEmpty(ControlID)) { _sb.Append("-" + ControlID); } _sb.Append(".cache"); return(_sb.ToString()); }