在mvc2下载文件时出错 [英] getting error while download the file in mvc2

查看:148
本文介绍了在mvc2下载文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我给了下载选项来下载该文件。当我正在检查本地服务器它是正常工作。但是在部署服务器之后,如果我点击链接意味着会显示以下错误,

In my site, i gave download option to download the file. when i am checking in local server it is working properly. But after deploy the server, if i click the link means it will show the following error,

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)
             };
         }


     }

这是我的码。我不知道这里有什么错误,任何人都可以找到我的问题并告诉我吗?

This is my code. I don't know what mistake here, Can anyone find my problem and tell me ?

推荐答案

在返回json时,你会丢失'JsonRequestBehavior.AllowGet'。

The Problem with ur code is that u r missing 'JsonRequestBehavior.AllowGet' while returning json.

  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)
         };
     }


 }

这篇关于在mvc2下载文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆