2014-06-17 41 views
0

在我的网站中,我给了下载选项来下载文件。当我在本地服务器检查它正在正常工作。但经过部署服务器,如果我点击链接意味着它会显示以下错误,在mvc2中下载文件时出现错误

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. 

我的代码在这里

public ActionResult Download(string fileName) 
     { 
     string pfn = Server.MapPath("~/Content/Files/" + fileName); 
     if (!System.IO.File.Exists(pfn)) 
     { 
      //throw new ArgumentException("Invalid file name or file not exists!"); 

      return Json(new JsonActionResult { Success = false, Message = "Invalid file name or file not exists!" }); 
     } 
     else 
     { 

      return new BinaryContentResult() 
      { 
       FileName = fileName, 
       ContentType = "application/octet-stream", 
       Content = System.IO.File.ReadAllBytes(pfn) 
      }; 
     } 


    } 

这是我的代码。我不知道这里有什么错误,有谁能找到我的问题并告诉我?

回答

0

与你的代码的问题是,你在返回json时缺少'JsonRequestBehavior.AllowGet'。

public ActionResult Download(string fileName) 
    { 
    string pfn = Server.MapPath("~/Content/Files/" + fileName); 
    if (!System.IO.File.Exists(pfn)) 
    { 
     //throw new ArgumentException("Invalid file name or file not exists!"); 

     return Json(new JsonActionResult { Success = false, Message = "Invalid file name or file not exists!" },JsonRequestBehavior.AllowGet }); 
    } 
    else 
    { 

     return new BinaryContentResult() 
     { 
      FileName = fileName, 
      ContentType = "application/octet-stream", 
      Content = System.IO.File.ReadAllBytes(pfn) 
     }; 
    } 


} 
+0

这会为你工作.. –

相关问题