示例#1
0
        /// <summary>
        /// Begins asynchronous ajax call handling
        /// </summary>
        /// <param name="context"></param>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback callback, object asyncState)
        {
            AjaxTask task    = null;
            string   ajaxCmd = context.Request["cmd"];

            //Check for purchase restrictions
            if (!string.IsNullOrEmpty(ajaxCmd))
            {
                task = CreateTask(ajaxCmd.ToLower());
            }

            if (task == null)
            {
                task = AjaxTask.NullTask;
            }

            //Assign task properties
            task.HttpContext   = context;
            task.AsyncCallback = callback;
            task.AsyncState    = asyncState;

            //Start the task
            task.Begin();

            //If task is not executing any async code then we need to call Finish() here
            if (task.AsyncWaitHandle == null)
            {
                task.AsyncCallback(task);
            }

            return(task);
        }
示例#2
0
        /// <summary>
        /// Called automatically when an ajax task is done executing
        /// NOTE: This function is called from the ThreadPool thread
        /// </summary>
        /// <param name="result"></param>
        public void EndProcessRequest(IAsyncResult result)
        {
            //A task has finished executing
            //Check Task.Status and proceed accordingly
            AjaxTask task = result as AjaxTask;

            task.Finish();

            //If there is a URL to redirect to then clear the response and only write the redirect url
            if (!string.IsNullOrEmpty(task.RedirectURL))
            {
                task.HttpContext.Response.Clear();
                task.HttpContext.Response.Write(task.RedirectURL);
            }
            else            // Add cache-control, pragma, and expires to prevent caching of Ajax content
            {
                task.HttpContext.Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
                task.HttpContext.Response.AppendHeader("Pragma", "no-cache");
                task.HttpContext.Response.AppendHeader("Expires", "0");
            }
        }