Created
September 18, 2015 16:00
-
-
Save cmatskas/bd87a36da0a5d4993a2b to your computer and use it in GitHub Desktop.
XmlHttpHandler.cs
This file contains 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
public class MySuperDuperHandler : IHttpHandler | |
{ | |
public void ProcessRequest(HttpContext context) | |
{ | |
var configService = new ConfigService(); | |
var page = new OutputCachedPage(new OutputCacheParameters | |
{ | |
Duration = 300, // in seconds | |
Location = OutputCacheLocation.Server, | |
VaryByParam = "None" | |
}); | |
page.ProcessRequest(HttpContext.Current); | |
XDocument doc = GetXmlData(); | |
context.Response.ContentType = "text/xml"; | |
context.Response.ContentEncoding = System.Text.Encoding.UTF8; | |
context.Response.Expires = -1; | |
context.Response.Cache.SetAllowResponseInBrowserHistory(true); | |
doc.Save(context.Response.Output); | |
} | |
public bool IsReusable | |
{ | |
get { return false; } | |
} | |
/// <summary> | |
/// Code required for server-side caching | |
/// </summary> | |
private sealed class OutputCachedPage : Page | |
{ | |
private readonly OutputCacheParameters cacheSettings; | |
public OutputCachedPage(OutputCacheParameters cacheSettings) | |
{ | |
// Tracing requires Page IDs to be unique. | |
ID = Guid.NewGuid().ToString(); | |
this.cacheSettings = cacheSettings; | |
} | |
protected override void FrameworkInitialize() | |
{ | |
base.FrameworkInitialize(); | |
InitOutputCache(cacheSettings); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment