1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Script.Serialization;
- using System.Web.Configuration;
- using System.Configuration;
- namespace EMIS.Web.Controls
- {
- public class ConfigurableJsonResult : JsonResult
- {
- public override void ExecuteResult(ControllerContext context)
- {
- if (context == null)
- {
- throw new ArgumentNullException("context");
- }
- if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
- String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
- {
- throw new InvalidOperationException("This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.");
- }
- HttpResponseBase response = context.HttpContext.Response;
- if (!String.IsNullOrEmpty(ContentType))
- {
- response.ContentType = ContentType;
- }
- else
- {
- response.ContentType = "application/json";
- }
- if (ContentEncoding != null)
- {
- response.ContentEncoding = ContentEncoding;
- }
- if (Data != null)
- {
- JavaScriptSerializer serializer = new JavaScriptSerializer();
- ScriptingJsonSerializationSection section = ConfigurationManager.GetSection("system.web.extensions/scripting/webServices/jsonSerialization") as ScriptingJsonSerializationSection;
- if (section != null)
- {
- serializer.MaxJsonLength = section.MaxJsonLength;
- serializer.RecursionLimit = section.RecursionLimit;
- }
- response.Write(serializer.Serialize(Data));
- }
- }
- }
- }
|