2012-08-12 2 views
2

사용자가 파일을 다운로드 할 수있게하려고하는데,이 기능을 사용하기 위해 아무런 노력을하지 않고 있습니다. 내가 사용 된 코드는 다음과 같습니다 내 디버깅 설정을 변경ASP.NET MVC의 응답에 헤더를 추가 할 수 없습니다.

A first chance exception of type 'System.Web.HttpException' occurred in System.Web.dll 
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.Mvc.dll 
A first chance exception of type 'System.Web.HttpException' occurred in System.Web.Mvc.dll 
A first chance exception of type 'System.NullReferenceException' occurred in WebDev.WebHost40.dll 

(등)

: 나는 예외를 많이 제외하고 실행 만들려고 할 때

Response.ClearHeaders(); 
Response.Clear(); 
Response.BufferOutput = true; 
Response.AddHeader("Content-disposition", 
        "attachment; filename= "+ Path.GetFileName(path) + fileType);      
Response.ContentType = "application/octet-stream"; 
Response.BinaryWrite(buffer); 
Response.Flush(); 
Response.Close(); 
Response.End(); 

불행하게도 아무 일도 발생하지 않습니다 내가 얻은 예외가 있다는 것을 발견했습니다.

"서버가 컨텐츠를 설정할 수 없습니다. ype HTTP 헤더를 보낸 후. "

Google을 통해 검색하고 많은 솔루션을 시도했지만 지금까지 아무 것도 작동하지 않았습니다. 이것은 내가 아는 한 Response가 사용 된 유일한 시간입니다. - 백그라운드 프로세스가 발생하지 않는 한 (만약 그렇다면 어떻게 변경합니까?). Asp.NET MVC를 사용하고 있습니다.

아이디어가 있으십니까?

편집

: 여기 문제를 해결하는 데 도움이 될 몇 가지 상황입니다 :

코드는 아약스, 나는 통해 서버 측 호출 할 필요가 있다고되는 이유를 통해 호출 된 WEBMETHOD 안에 클라이언트 측 (나쁜 습관, 그러나 그것은 제공된 시간에 필요했습니다) 그리고 나는 또한 매개 변수를 통과해야했습니다.

$("#Button").each(function() { 
       this.submitting = false; //To prevent double-clicking problems 
      }).on("click", function (e) { 
       if (e.preventDefault) e.preventDefault(); 
       $.ajaxSetup({ cache: false }); 
       e.preventDefault(); 
       if (!this.submitting) 
       { 
        this.submitting = true; 
        var self = this; 
        $.ajax({ 
         url: 'Controller/retrieveFile', 
         type: 'POST', 
         data: { SystemNumber: $("#Button").val() }, 
         dataType: 'json', 
         success: function (data) { 
          self.submitting = false; 
         }, 
         error: function() { 
          self.submitting = false; 
         } 
        }); 
       } 
      }); 

아마도이되어, 반환 값에 문제가 : 여기

는 AJAX 호출입니까? 현재 내가

를 반환하고
Json(true, JsonRequestBehavior.AllowGet); 
+0

전체 흐름에서 '응답'코드가 맞는 위치를 표시 할 수 있습니까? 에서, 어떤 컨트롤러 방법으로? 문맥에서 문제를 진단하는 것은 어렵습니다. –

+0

나는 단지 그것을 생각하고 있었다! 잠시만 기다려주십시오 :) –

+0

질문이 업데이트되었습니다. –

답변

0

TRY) (("내용 - 처리", ....) HttpContext.Response.AppendHeader을 사용하고 Response.ClearHeaders 치우는; 및 Response.Clear(); 윤곽.

또한 메서드의 반환 형식으로 FileContentResult를 사용해야합니다.

관련 문제