コード例 #1
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="context">The current http context.</param>
        public void ProcessRequest(HttpContext context)
        {
            PreProcessRequest(context);

            // Set the content type of the http response to plain text.
            context.Response.ContentType = "text/plain";

            // Check if the generic handler requires an authenticated session.
            if (this.RequiresAuthentication)
            {
                // Check if the current session has an authenticated user.
                if (HttpContext.Current.Session["User"] == null)
                {
                    if (this.OnSessionError != null)
                    {
                        this.OnSessionError(context, new EventArgs());
                    }
                    else
                    {
                        throw new Exception("Not authenticated.");
                    }

                    return;
                }
            }

            if (this.RequiresWhitelist)
            {
                Whitelist whitelist = new Whitelist();

                if (!whitelist.Valid(context.Request.ServerVariables["REMOTE_HOST"]))
                {
                    throw new Exception("Access denied [" + context.Request.ServerVariables["REMOTE_HOST"] + "].");
                }
            }

            // Get the requested method name from the http request.
            string method = context.Request.Params["Method"];

            // Check if the requested method exists.
            if (!this.Methods.ContainsKey(method))
            {
                throw new NotImplementedException();
            }

            // Invoke the requested method.
            this.Methods[method].Invoke(context);
        }