-
-
Save jbouy/6349313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Determines if GZip is supported | |
/// </summary> | |
/// <returns></returns> | |
public static bool IsGZipSupported() | |
{ | |
string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"]; | |
if (!string.IsNullOrEmpty(AcceptEncoding) && | |
(AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate"))) | |
return true; | |
return false; | |
} | |
/// <summary> | |
/// Sets up the current page or handler to use GZip through a Response.Filter | |
/// IMPORTANT: | |
/// You have to call this method before any output is generated! | |
/// </summary> | |
public static void GZipEncodePage() | |
{ | |
HttpResponse Response = HttpContext.Current.Response; | |
if (IsGZipSupported()) | |
{ | |
string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"]; | |
if (AcceptEncoding.Contains("deflate")) | |
{ | |
Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter, | |
System.IO.Compression.CompressionMode.Compress); | |
Response.Headers.Remove("Content-Encoding"); | |
Response.AppendHeader("Content-Encoding", "deflate"); | |
} | |
else | |
{ | |
Response.Filter = new System.IO.Compression.GZipStream(Response.Filter, | |
System.IO.Compression.CompressionMode.Compress); | |
Response.Headers.Remove("Content-Encoding"); | |
Response.AppendHeader("Content-Encoding", "gzip"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Page_Load(object sender, EventArgs e) | |
{ | |
WebUtils.GZipEncodePage(); | |
Entry = WebLogFactory.GetEntry(); | |
var entries = Entry.GetLastEntries(App.Configuration.ShowEntryCount, "pk,Title,SafeTitle,Body,Entered,Feedback,Location,ShowTopAd", "TEntries"); | |
if (entries == null) | |
throw new ApplicationException("Couldn't load WebLog Entries: " + Entry.ErrorMessage); | |
this.repEntries.DataSource = entries; | |
this.repEntries.DataBind(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment