/// <summary>
        /// Handles the json format.
        /// </summary>
        /// <param name="currentPage">The current page.</param>
        /// <param name="httpContextBase">The HttpContext</param>
        public static void HandleJson(PageData currentPage, HttpContextBase httpContextBase = null)
        {
            if (currentPage.CannotBeUsedInOutput())
            {
                return;
            }

            JsonOutputFormat jsonOutputFormat = new JsonOutputFormat();

            jsonOutputFormat.HandleFormat(currentPage, httpContextBase ?? new HttpContextWrapper(HttpContext.Current));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates the response.
        /// </summary>
        /// <param name="requestedPageData">
        /// The requested page data.
        /// </param>
        /// <returns>
        /// The requested content.
        /// </returns>
        /// <exception cref="System.Web.Http.HttpResponseException">
        /// A response exception.
        /// </exception>
        private string GenerateResponse(PageData requestedPageData)
        {
            if (this.CurrentHttpContext.IsJsonAccepted())
            {
                if (WebApiSettings.Instance.EnableJSON)
                {
                    return(JsonOutputFormat.GenerateJson(requestedPageData));
                }

                throw new HttpResponseException(HttpStatusCode.NotAcceptable);
            }

            if (this.CurrentHttpContext.IsXmlAccepted())
            {
                if (WebApiSettings.Instance.EnableXML)
                {
                    return(XmlOutputFormat.GenerateXml(requestedPageData));
                }

                throw new HttpResponseException(HttpStatusCode.NotAcceptable);
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }