using System; using System.Configuration; using System.Globalization; using System.IO.Compression; using System.Threading; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using ScrewTurn.Wiki.PluginFramework; namespace ScrewTurn.Wiki { public class BasePage : Page { public BasePage() { } protected override void OnInit(EventArgs e) { base.OnInit(e); // Mitigate Cross-Site Request Forgery (CSRF/XSRF) attacks ViewStateUserKey = Session.SessionID; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Bypass compression if the current request was made by Anthem.NET if(HttpContext.Current.Request["Anthem_CallBack"] != null) return; // Request might not be initialized -> use HttpContext string ua = HttpContext.Current.Request.UserAgent != null ? HttpContext.Current.Request.UserAgent.ToLowerInvariant() : ""; if(Settings.EnableHttpCompression && !ua.Contains("konqueror") && !ua.Contains("safari")) { if(Request.Headers["Accept-encoding"] != null && Request.Headers["Accept-encoding"].Contains("gzip")) { Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress, true); Response.AppendHeader("Content-encoding", "gzip"); Response.AppendHeader("Vary", "Content-encoding"); //Response.Write("HTTP Compression Enabled (GZip)"); } else if(Request.Headers["Accept-encoding"] != null && Request.Headers["Accept-encoding"].Contains("deflate")) { Response.Filter = new DeflateStream(Response.Filter, CompressionMode.Compress, true); Response.AppendHeader("Content-encoding", "deflate"); Response.AppendHeader("Vary", "Content-encoding"); //Response.Write("HTTP Compression Enabled (Deflate)"); } } } protected override void InitializeCulture() { // First, look for hard-stored user preferences // If they are not available, look at the cookie string culture = Preferences.LoadLanguageFromUserData(); if(culture == null) culture = Preferences.LoadLanguageFromCookie(); if(culture != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); } else { try { if(Settings.DefaultLanguage.Equals("-")) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); } else { Thread.CurrentThread.CurrentCulture = new CultureInfo(Settings.DefaultLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.DefaultLanguage); } } catch { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); } } //Response.Write("Culture: " + Thread.CurrentThread.CurrentCulture.Name + "
"); //Response.Write("UICulture: " + Thread.CurrentThread.CurrentUICulture.Name + "
"); } /// /// Detects the correct object associated to the current page using the Page and NS parameters in the query string. /// /// true to load the default page of the specified namespace when Page is not specified, false otherwise. /// If Page is specified and exists, the correct , otherwise null if loadDefault is false, /// or the object representing the default page of the specified namespace if loadDefault is true. protected PageInfo DetectPageInfo(bool loadDefault) { return Tools.DetectCurrentPageInfo(loadDefault); } /// /// Detects the full name of the current page using the Page and NS parameters in the query string. /// /// The full name of the page, regardless of the existence of the page. protected string DetectFullName() { return Tools.DetectCurrentFullName(); } /// /// Detects the correct object associated to the current namespace using the NS parameter in the query string. /// /// The correct object, or null. protected NamespaceInfo DetectNamespaceInfo() { return Tools.DetectCurrentNamespaceInfo(); } /// /// Detects the name of the current namespace using the NS parameter in the query string. /// /// The name of the namespace, or an empty string. protected string DetectNamespace() { return Tools.DetectCurrentNamespace(); } } }