/// <summary> /// Returns an instance of a class that implements the <see cref="T:System.Web.IHttpHandler"></see> interface. /// </summary> /// <param name="context">An instance of the <see cref="T:System.Web.HttpContext"></see> class that provides references to intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> /// <param name="requestType">The HTTP data transfer method (GET or POST) that the client uses.</param> /// <param name="url">The <see cref="P:System.Web.HttpRequest.RawUrl"></see> of the requested resource.</param> /// <param name="pathTranslated">The <see cref="P:System.Web.HttpRequest.PhysicalApplicationPath"></see> to the requested resource.</param> /// <returns> /// A new <see cref="T:System.Web.IHttpHandler"></see> object that processes the request. /// </returns> public IHttpHandler GetHandler( HttpContext context, string requestType, string url, string pathTranslated) { if (url.EndsWith("logout.aspx")) { FormsAuthentication.SignOut(); context.Response.Redirect(CMSContext.Current.ResolveUrl("~")); context.Response.End(); } string outline = url; if (CMSContext.Current.AppPath.Length != 1) { outline = outline.Substring(CMSContext.Current.AppPath.Length); } // Outline must start with "/", so add it if we are missing if (!outline.StartsWith("/", StringComparison.Ordinal)) { outline = "/" + outline; } // Set the outline CMSContext.Current.Outline = outline; // Load current outline bool isFolder = false; int folderId = 0; int pageId = -1; string masterFile = String.Empty; string cacheKey = CmsCache.CreateCacheKey("filetree", CMSContext.Current.SiteId.ToString(), outline); DataTable fileTreeItemTable = null; // check cache first object cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { fileTreeItemTable = (DataTable)cachedObject; } if (fileTreeItemTable == null) { lock (CmsCache.GetLock(cacheKey)) { cachedObject = CmsCache.Get(cacheKey); if (cachedObject != null) { fileTreeItemTable = (DataTable)cachedObject; } else { fileTreeItemTable = FileTreeItem.GetItemByOutlineAllDT(outline, CMSContext.Current.SiteId); if (fileTreeItemTable.Rows.Count > 0) { CmsCache.Insert(cacheKey, fileTreeItemTable, CmsConfiguration.Instance.Cache.PageDocumentTimeout); } } } } if (fileTreeItemTable != null && fileTreeItemTable.Rows.Count > 0) { DataRow row = fileTreeItemTable.Rows[0]; folderId = (int)row[0]; CMSContext.Current.PageId = folderId; isFolder = (bool)row[4]; masterFile = (string)row[8]; if (String.Compare(outline, (string)row[2], true, CultureInfo.InvariantCulture) == 0) { pageId = (int)row[0]; } } /* * using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId)) * { * if (reader.Read()) * { * folderId = reader.GetInt32(0); * CMSContext.Current.PageId = folderId; * isFolder = reader.GetBoolean(4); * masterFile = reader.GetString(8); * if (String.Compare(outline, reader.GetString(2), true, CultureInfo.InvariantCulture) == 0) * { * pageId = reader.GetInt32(0); * } * } * * reader.Close(); * } * */ //if (FileTreeItem.IsVirtual(outline)) if (pageId != -1) // is this folder/page virtual? { // If URL is not rewritten, then save the one originally requested if (!CMSContext.Current.IsUrlReWritten) { CMSContext.Current.IsUrlReWritten = true; if (HttpContext.Current.Request.QueryString.Count == 0) { CMSContext.Current.CurrentUrl = url; } else { CMSContext.Current.CurrentUrl = String.Format(url + "?" + HttpContext.Current.Request.QueryString); } } /* * bool isFolder = false; * int folderId = 0; * string masterFile = String.Empty; * * using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId)) * { * if (reader.Read()) * { * folderId = reader.GetInt32(0); * isFolder = reader.GetBoolean(4); * masterFile = reader.GetString(8); * } * } * */ if (!isFolder) { Uri rawUrl = BuildUri(String.Format("~/template.aspx"), HttpContext.Current.Request.IsSecureConnection); string filePath; string sendToUrlLessQString; string sendToUrl = rawUrl.PathAndQuery; RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath); return(PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context)); } else { string newUrl = String.Empty; //try to find default page for folder using (IDataReader reader = FileTreeItem.GetFolderDefaultPage(folderId)) { if (reader.Read()) { newUrl = Mediachase.Commerce.Shared.CommerceHelper.GetAbsolutePath(reader.GetString(2)); } else { reader.Close(); throw new HttpException(204, "Default page for folder not found"); } reader.Close(); } Uri rawUrl = BuildUri(newUrl, HttpContext.Current.Request.IsSecureConnection); string filePath; string sendToUrlLessQString; string sendToUrl = rawUrl.PathAndQuery; RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath); return(PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context)); } } else if (!string.IsNullOrEmpty(pathTranslated)) { return(PageParser.GetCompiledPageInstance(url, pathTranslated, context)); } else { return (PageParser.GetCompiledPageInstance( url, context.Server.MapPath("~"), context)); } }