2009-03-25 7 views
0

여러 PDF 파일이있는 웹 사이트가 있습니다. 익명 사용자를 거부하는 web.config가있는 폴더에서 표준 ASP.NET 인증을 사용하여 이들 중 상당수를 잠궈 야합니다. ASP.NET의 PDF 권한 관리 - 제한 시간 문제

나는 ASP.NET 작업자 프로세스에 의해 처리하려면 PDF 파일을 설정하고 추가 :

<add type="System.Web.StaticFileHandler" path="*.pdf" verb="*" /> 

을 내 Web.config의에 있지만 다운로드 할 때 몇 가지 이유로 그들은 끊습니다. 나는 이전 서버에서이 문제를 보았습니다. 그리고 저의 삶에 대해 나는 그것을 해결하기 위해 무엇을했는지 기억하지 못합니다. 누구 아이디어가 있습니까?

감사합니다.

+0

나는 이것을하지 않는다 (나는 스트림 pdf의 tho를한다); 나는 바이올린을 설치하고 서버에서 오는 속도와 속도를 확인하는 것이 좋습니다. 적어도 당신은 일할 수있는 정보를 얻을 것입니다. 또한 PDF 파일을 잠글 수 있습니까? – Will

답변

0

필자가 열어서 실제로 어떤 요청이 서버로 전송되었고 응답이 무엇인지 확인했습니다. 또한 실제로 요청하는 방법 (예 : 경로)과 PDF를 제공하는 방법에 따라 다를 수 있습니다. 필자는 WROX 전자 책 중 하나에서 암호로 보호 된 PDF 문서를 반환하는 방법과 사용자 그룹에서 수행하는 처리기 및 모듈 프레젠테이션을 보여줍니다. http://professionalaspnet.com/archive/2008/08/10/CodeStock-Rocked_2100_.aspx (링크를 페이지의 코드를 다운로드).

다음은 Handler를 사용하여 PDF를 반환하는 코드입니다. 도움이 될 것입니다.

'First run the supplied filename through a URL decoder to change any URL 
    'characters back to their normal selves. 
    sDocument = HttpUtility.UrlDecode(_ 
     Path.GetFileName(context.Request.Url.ToString)) 
    'Now build a full physical path to the file on the server. 
    sDocument = Path.Combine(Path.Combine(_ 
     context.Request.PhysicalApplicationPath, "PDF"), sDocument) 

    'Verify we actually have the file to serve. 
    If File.Exists(sDocument) = False Then 
     context.Server.Transfer("badpdf.aspx") 
    End If 

     'The next two sections are from Scott Hanselman's blog, but seem to be out of date, 
    'since it was posted in 2003 
    'http://www.hanselman.com/blog/InternetExplorerAndTheMagicOfMicrosoftKBArticleQ293792.aspx 
    'This is done to support older browsers that were not as efficient 
    'at managing document requests. 
    If InStr(1, context.Request.UserAgent, "contype") > 0 Then 
     'Just send the mime/type 
     Response.ContentType = "application/pdf" 
     Response.End() 
     Exit Sub 
    End If 

    Dim Language As String = context.Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") 
    If String.IsNullOrEmpty(Language) Then 
     Response.Clear() 
     Response.ContentType = "application/pdf" 
     Response.AddHeader("Last-modified", "Mon, 01 Sep 1997 01:03:33 GMT") 
     Response.Status = "304 Not Modified" 
     Response.End() 
     Exit Sub 
    End If 

    'Set the Cacheability 
    Response.Cache.SetCacheability(HttpCacheability.Public) 
    Response.Cache.SetExpires(DateTime.MinValue) 
    Response.ContentType = "application/pdf" 

    'This opens the Open/Save Dialog 
    Response.AddHeader("Content-Disposition", "attachment; filename=" & _ 
    Path.GetFileName(sDocument)) 

    'This Bypasses the Open/Save Dialog 
    'Response.AddHeader("Content-Disposition", "inline; filename=" & _ 
    ' Path.GetFileName(sDocument)) 

    If File.Exists(sDocument) Then 
     'Write the file to the Response Output stream without buffering. 
     'This is new to ASP.NET 2.0. Prior to that use WriteFile. 
     Response.TransmitFile(sDocument) 
     Response.End() 
    End If 
0

나는 내가 무엇을 놓쳤는지를 마침내 알았습니다. application/pdf 대신 PDF 파일의 MIME 유형을 application/octet-stream으로 설정해야했습니다.