2010-02-28 33 views
39

Tôi không hiểu lỗi này, không tạo ra lỗi trong "JsonResult Test()", Tôi đang làm dự án khác như ASP.NET MVCASP.NET MVC 2 - Không có phản ứng jquery ajax

Cảm ơn

Lỗi:

System.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. 

[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.] 
    System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +263733 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10 
    System.Web.Mvc.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11() +20 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251 
    System.Web.Mvc.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13() +19 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314 
    System.Web.Mvc.Controller.ExecuteCore() +105 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8678910 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

C#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

namespace Tesis.Controllers 
{ 
    public class AnalysisSourceDataController : Controller 
    { 
     // 
     // GET: /AnalysisSourceData/ 

     public ActionResult Index() 
     { 
      return View(); 
     } 

     public JsonResult Test() 
     { 
      return Json(new { mymsg = "my msg" }); 
     } 
    } 
} 

javascript
<script type="text/javascript"> 
    $(function() { 
     $.getJSON("/AnalysisSourceData/Test", function(data) { 
      alert(data.mymsg); 
     }); 
    }); 
</script> 

Trả lời

65

bạn không hiểu gì? Lỗi này khó có thể mô tả hơn. Đó là một tính năng bảo mật để ngăn JSON hijacking, bạn có thể vô hiệu hóa nó như thế này ..

return Json(new { mymsg = "my msg" }, JsonRequestBehavior.AllowGet); 

nhưng bạn nên hiểu được implications.

+0

Tôi không hiểu rằng các dự án khác mà tôi không cần tham số này. –

+6

Đây là một tính năng được thêm vào với ASP.NET MVC2 trong các dự án MVCv1 bạn không cần phải thêm nó. Việc thêm tính năng này chỉ khiến mọi người dừng lại và nghĩ họ đang làm gì trước khi hiển thị dữ liệu JSON qua GET (có một số ứng dụng hoàn toàn hợp lệ). –

+0

Cảm ơn bạn, tôi bỏ lỡ xem tài liệu –

Các vấn đề liên quan