protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
// Init private fields
_threadAbortExceptionThrown = false;
_request = context.Request;
_response = context.Response;

// Create a new context and add it to the items collection for later retrieval
// by MagicAjaxContext.Current
_magicAjaxContext = new MagicAjaxContext();
HttpContext.Current.Items.Add(MagicAjaxContext.ContextKey, _magicAjaxContext);
// Check if the request is for the embedded AjaxCallObject.js script
if (context.Request.RawUrl.EndsWith("AjaxCallObject.js.aspx"))
{
context.Response.ContentType = "text/javascript";
object cachedAjaxCallObjectJs = context.Cache["__CACHED_AJAXCALLOBJECT_JS"];
if (cachedAjaxCallObjectJs == null)
{
//read and output the embedded AjaxCallObject.js file from the manifest
using (System.IO.StreamReader reader = new System.IO.StreamReader(typeof(MagicAjaxModule).Assembly.GetManifestResourceStream("MagicAjax.script.AjaxCallObject.js")))
{
cachedAjaxCallObjectJs = reader.ReadToEnd();
}
context.Cache.Insert("__CACHED_AJAXCALLOBJECT_JS", cachedAjaxCallObjectJs);
}
context.Response.Write(cachedAjaxCallObjectJs);
context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
context.Response.End();
}
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
// Init private fields
_threadAbortExceptionThrown = false;
_request = context.Request;
_response = context.Response;
_response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
// Create a new context and add it to the items collection for later retrieval
// by MagicAjaxContext.Current
_magicAjaxContext = new MagicAjaxContext();
HttpContext.Current.Items.Add(MagicAjaxContext.ContextKey, _magicAjaxContext);
// Check if the request is for the embedded AjaxCallObject.js script
if (context.Request.RawUrl.EndsWith("AjaxCallObject.js.aspx"))
...