public
class
BasePage : Page
{
public BasePage() {
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// Request might not be initialized -> use HttpContext
string ua = HttpContext.Current.Request.UserAgent != null ? HttpContext.Current.Request.UserAgent.ToLower() : "";
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() {
if(Request.Cookies[Settings.CultureCookieName] != null) {
HttpCookie cookie = Request.Cookies[Settings.CultureCookieName];
string culture = cookie["C"];
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 + "<br />");
//Response.Write("UICulture: " + Thread.CurrentThread.CurrentUICulture.Name + "</br >");
}
}
public BasePage() {
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// Request might not be initialized -> use HttpContext
string ua = HttpContext.Current.Request.UserAgent != null ? HttpContext.Current.Request.UserAgent.ToLower() : "";
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() {
if(Request.Cookies[Settings.CultureCookieName] != null) {
HttpCookie cookie = Request.Cookies[Settings.CultureCookieName];
string culture = cookie["C"];
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 + "<br />");
//Response.Write("UICulture: " + Thread.CurrentThread.CurrentUICulture.Name + "</br >");
}
}
public
static
class
Compressor
{
/// <summary>
/// Compresses data.
/// </summary>
/// <param name="data">The data to compress.</param>
/// <returns>The compressed data.</returns>
public static byte[] Compress(byte[] data) {
MemoryStream output = new MemoryStream();
GZipStream gzip = new GZipStream(output, CompressionMode.Compress, true);
gzip.Write(data, 0, data.Length);
gzip.Close();
return output.ToArray();
}
/// <summary>
/// Decompresses data.
/// </summary>
/// <param name="data">The data to decompress.</param>
/// <returns>The decompressed data.</returns>
public static byte[] Decompress(byte[] data) {
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true);
MemoryStream output = new MemoryStream();
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while(read > 0) {
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}
}
/// <summary>
/// Compresses data.
/// </summary>
/// <param name="data">The data to compress.</param>
/// <returns>The compressed data.</returns>
public static byte[] Compress(byte[] data) {
MemoryStream output = new MemoryStream();
GZipStream gzip = new GZipStream(output, CompressionMode.Compress, true);
gzip.Write(data, 0, data.Length);
gzip.Close();
return output.ToArray();
}
/// <summary>
/// Decompresses data.
/// </summary>
/// <param name="data">The data to decompress.</param>
/// <returns>The decompressed data.</returns>
public static byte[] Decompress(byte[] data) {
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true);
MemoryStream output = new MemoryStream();
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while(read > 0) {
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}
}