2009-03-25 12 views
0

私はいくつかのPDFファイルを持つWebサイトを持っています。私はそれらのかなりの数を標準のASP.NET認証(匿名ユーザーを拒否するweb.configのあるフォルダ内)でロックダウンする必要があります。ASP.NETでのPDF権限管理 - タイムアウトの問題

私は、ASP.NETワーカープロセスによって処理取得するPDFファイルを設定して、コメントを追加しました:

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

を私のweb.configファイルに、しかし、ダウンロードする際に、彼らがハングアップする、いくつかの理由があります。私は古いサーバー上でこの問題を以前に見てきました。私の生きているところでは、私がそれを解決するために何をしたのか覚えていません。誰にも分かりますか?

ありがとうございました。

+0

私はこれをしません(私はストリームpdfのthoを行います)。私は、フィドラーをインストールし、何がサーバーからどのような速度で降りてくるのかを見てみましょう。少なくともあなたは仕事をするための情報を得るでしょう。また、PDFファイルをロックすることはできますか? – Will

答えて

0

私はフィドラーを開き、実際にどのようなリクエストがサーバーに送信されたのか、そしてその応答が何であるかを確認します。また、実際にどのようにリクエストしているか(つまりパス)やPDFをどのように提供しているかによっても異なります。 WROX eBookの1つと、ユーザーグループで行うハンドラとモジュールのプレゼンテーションで、パスワードで保護されたPDFドキュメントを返す方法を示します。 http://professionalaspnet.com/archive/2008/08/10/CodeStock-Rocked_2100_.aspx(ページ上のコードをダウンロードするリンク)。

ここでは、ハンドラを使用して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ではなくapplication/octet-streamにPDFファイルのMIMEタイプを設定する必要がありました。

関連する問題