本文整理汇总了C#中System.Web.Mvc.JsonResult.ExecuteResult方法的典型用法代码示例。如果您正苦于以下问题:C# JsonResult.ExecuteResult方法的具体用法?C# JsonResult.ExecuteResult怎么用?C# JsonResult.ExecuteResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.JsonResult
的用法示例。
在下文中一共展示了JsonResult.ExecuteResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application_Error
protected void Application_Error()
{
var httpContext = HttpContext.Current;
if (httpContext == null) return;
var context = new HttpContextWrapper(System.Web.HttpContext.Current);
var routeData = RouteTable.Routes.GetRouteData(context);
var requestContext = new RequestContext(context, routeData);
/* when the request is ajax the system can automatically handle a mistake with a JSON response. then overwrites the default response */
if (requestContext.HttpContext.Request.IsAjaxRequest())
{
httpContext.Response.Clear();
var controllerName = requestContext.RouteData.GetRequiredString("controller");
var factory = ControllerBuilder.Current.GetControllerFactory();
var controller = factory.CreateController(requestContext, controllerName);
var controllerContext = new ControllerContext(requestContext, (ControllerBase)controller);
var jsonResult = new JsonResult
{
Data = new {success = false, serverError = "500"},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
jsonResult.ExecuteResult(controllerContext);
httpContext.Response.End();
}
else
{
httpContext.Response.Redirect("~/Error");
}
}
示例2: OnException
public override void OnException(ExceptionContext exceptionContext)
{
base.OnException(exceptionContext);
logError(exceptionContext);
// inform elmah
var httpContext = exceptionContext.HttpContext.ApplicationInstance.Context;
var signal = ErrorSignal.FromContext(httpContext);
signal.Raise(exceptionContext.Exception, httpContext);
// change the result if an ajax request
var request = exceptionContext.HttpContext.Request;
if (request.IsAjaxRequest() == false)
return;
var jsonDto = new Harbor.UI.Models.InternalServerErrorDto
{
exception = exceptionContext.Exception.Message,
exceptionType = exceptionContext.Exception.GetType().FullName
};
#if DEBUG
jsonDto.stackTrace = exceptionContext.Exception.StackTrace;
#endif
var jsonResult = new JsonResult {Data = jsonDto, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
exceptionContext.HttpContext.Response.Clear();
exceptionContext.Result = jsonResult;
//exceptionContext.HttpContext.Response.StatusCode = 500;
exceptionContext.ExceptionHandled = true;
jsonResult.ExecuteResult(exceptionContext);
exceptionContext.HttpContext.Response.End();
}
示例3: OnException
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.HttpContext.IsCustomErrorEnabled || true) //IsCustomErrorEnabled always false if client is localhost or client and server IPs identical. True set to override.
{
filterContext.ExceptionHandled = true;
// If this is an ajax request, return the exception in the response
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
//if (HttpContext.Response.ContentType == "text/html")
//{
// filterContext.HttpContext.Response.StatusCode = 500;
// var json = new JsonResult();
// json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
// json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
// json.ExecuteResult(this.ControllerContext);
//}
//else
//{
filterContext.HttpContext.Response.StatusCode = 500;
var json = new JsonResult();
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; //SICHERHEITSPROBLEM: s. http://haacked.com/archive/2009/06/25/json-hijacking.aspx
json.Data = HttpUtility.UrlEncode(filterContext.Exception.Message); // +filterContext.Exception.StackTrace;
json.ExecuteResult(this.ControllerContext);
//}
}
else
{
ViewData.Model = new System.Web.Mvc.HandleErrorInfo(filterContext.Exception, "ControllerName", "ActionName");
// Pass a flag to the view to tell it whether or not to show a the stack trace
ViewBag.IsCustomErrorEnabled = true; //filterContext.HttpContext.IsCustomErrorEnabled;
this.View("Error").ExecuteResult(this.ControllerContext);
}
}
}
示例4: Execute
public override void Execute(object model, ControllerContext context)
{
context.HttpContext = new HttpContextWrapper(HttpContext.Current);
var result = new JsonResult {Data = model};
result.ExecuteResult(context);
}
示例5: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
JsonResult result = new JsonResult();
result.Data = GetResult(context);
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
result.ExecuteResult(context);
}
示例6: RenderAjaxView
protected virtual void RenderAjaxView(HttpRequestBase request, Exception currentError)
{
var jsonResult = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new {error_message = GetJsonErrorMessage(request, currentError)}
};
jsonResult.ExecuteResult(NewControllerContext(request));
}
示例7: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var result = new JsonResult
{
Data = Data,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
result.ExecuteResult(context);
}
示例8: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var jsonResponse = new JsonResult
{
Data = this,
ContentType = "application/json",
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
jsonResponse.ExecuteResult(context);
}
示例9: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var response = new JsonResponse
{
FatalErrorUrl = _fatalErrorUrl,
ValidationErrorMessage = _validationErrorMessage,
Data = _data, Success = string.IsNullOrWhiteSpace(_validationErrorMessage)
};
var json = new JsonResult
{
Data = response,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
json.ExecuteResult(context);
}
示例10: OnException
public override void OnException(ExceptionContext context)
{
if (IsAjaxCall)
{
context.ExceptionHandled = true;
var jsonResult = new JsonResult();
jsonResult.Data = new {Message = context.Exception.Message , MessageType = "Error"};
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
jsonResult.ExecuteResult(context);
}
else
{
// if not an ajax request, continue with logic implemented by MVC -> html error page
base.OnException(context);
}
}
示例11: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
if (context.RequestContext.HttpContext.Request.IsAjaxRequest())
{
string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
JsonResult result = new JsonResult()
{
Data = new{LoggedOut=true,RedirectUrl = destinationUrl},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
result.ExecuteResult(context);
}
else
base.ExecuteResult(context);
}
示例12: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var contentType = context.RequestContext.HttpContext.Request.Headers["Accept"];
if (contentType != null && contentType.Contains("application/json"))
{
if (Model is IEnumerable && !(Model is string))
{
Model = new CollectionWrapper { Collection = (IEnumerable)Model };
}
var result = new JsonResult { Data = Model, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
result.ExecuteResult(context);
}
else
{
context.Controller.ViewData.Model = Model;
var result = new ViewResult { ViewData = context.Controller.ViewData };
result.ExecuteResult(context);
}
}
示例13: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var cr = new ContentResult();
if (Mode == RenderMode.Html)
{
cr.ContentType = "text/html";
cr.Content = mHTML;
}
else if (Mode == RenderMode.Text)
{
cr.ContentType = "text/plain";
cr.Content = mText;
}
else if (Mode == RenderMode.Json)
{
JsonResult jr = new JsonResult();
jr.Data = new
{
mMessage.From,
mMessage.To,
mMessage.CC,
mMessage.Bcc,
mMessage.Headers,
mMessage.Priority,
mMessage.ReplyToList,
mMessage.Sender,
mMessage.Subject,
mMessage.SubjectEncoding
};
jr.ExecuteResult(context);
return;
}
else
{
new SmtpClient().Send(mMessage);
if (Mode == RenderMode.SendWithJson)
{
var jr = new JsonResult();
jr.Data = new { success = true };
jr.ExecuteResult(context);
return;
}
cr.Content = "OK";
}
cr.ExecuteResult(context);
}
示例14: RenderAjaxView
private static void RenderAjaxView(HttpApplication httpApplication, HttpStatusCode httpStatusCode,
Exception currentError)
{
// Ok. lets check if this content type contains a request for json.
string errorMessage = httpApplication.Request.ContentType.Contains("json")
? currentError.Message
: string.Format(
"An error occured but we are unable to handle the request.ContentType [{0}]. Anyways, the error is: {1}",
httpApplication.Request.ContentType,
currentError.Message);
var errorController = new FakeErrorController();
var controllerContext =
new ControllerContext(httpApplication.Context.Request.RequestContext, errorController);
var jsonResult = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
error_message = errorMessage
}
};
jsonResult.ExecuteResult(controllerContext);
// Lets make sure we set the correct Error Status code :)
httpApplication.Response.StatusCode = (int) httpStatusCode;
}
示例15: ExecuteResult
/// <summary>
/// 执行
/// </summary>
/// <param name="context"></param>
public override void ExecuteResult(ControllerContext context)
{
var model = new
{
status = Status,
message = Message,
data = Data,
url = Url
};
var result = new JsonResult
{
Data = model,
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
MaxJsonLength = 104857600 //100MB
};
result.ExecuteResult(context);
}