.Net 1.1 に組み込まれたアプリケーションを使用して、サーバー上の PDF、PPT、DOC、コンテンツへの匿名アクセスをブロックする必要があります。IIS 5.1。IIS で匿名アクセスのチェックを外してみましたが、うまくいきません。
1 に答える
0
これが古い投稿であることは承知しています。うまくいけば、.Net 1.1 から離れているか、適切な解決策を見つけていることを願っています。しかし、うまくいけば、これはあなたや他の誰かを助けるでしょう. 私の考えは、PDF を Web フォルダーの外に移動し、リンクをダウンロード ハンドラーに変更することです。ハンドラーで、訪問者がログインしていることを確認し、PDF へのアクセスを許可または禁止することができます。簡単な例は次のとおりです。
リンク:http://mysite/download.ashx?path=secure_folder/my.pdf
ハンドラーには以下が含まれる場合があります。
Public Class Download : Implements IHttpHandler
Implements SessionState.IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
If User.IsLoggedIn() Then
'implement your own user validation here
Dim path as String = "E:\" & Request.QueryString(path).Replace("/", "\")
Using fs As IO.FileStream = New IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim fileLen As Long = fs.Length()
Dim fileData(fileLen) As Byte
fs.Read(fileData, 0, Integer.Parse(fileLen.ToString()))
context.Response.ContentType("application/pdf") 'set as appropriate based on file extension
context.Response.BinaryWrite(fileData)
End Using
Else
context.Response.Write("You don't have access to this resource.")
End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
于 2014-06-20T18:28:32.353 に答える