【问题标题】:How to secure pdf content on a server in .net 1.1 IIS5.1如何在 .net 1.1 IIS5.1 中保护服务器上的 pdf 内容
【发布时间】:2013-11-11 11:17:59
【问题描述】:

我需要通过 .Net 1.1 内置的应用程序阻止对服务器上的 PDF、PPT、DOC、内容的匿名访问; IIS 5.1。我曾尝试取消选中 IIS 中的匿名访问,但它不起作用。

【问题讨论】:

  • 我原以为您的首要任务是确保升级。 .NET 1.1 甚至没有 extended 支持。 IIS 5.1 在 6 个月后不再提供扩展支持。
  • 是的,我知道我需要升级,但在它准备好之前,我需要保护我的内容...任何建议都会有很大帮助。

标签: c# asp.net vb.net iis asp.net-1.1


【解决方案1】:

我知道这是一篇旧帖子,希望您离开 .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

【讨论】:

  • 好主意,但是如何让处理程序处理大文件?如果您不想让我投反对票,您还可以将 FileStream 放入 Using 块中。
  • 感谢您接听那个约翰。我的格式在编辑时出现了问题。不知道为什么。
  • 没有反对意见,但这对于大文件仍然不太适用。仔细阅读 3Gb 文件的代码,你就会明白我的意思(假设 3Gb 将构成一个大 PDF)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2014-12-23
  • 2012-01-05
  • 1970-01-01
  • 2014-01-05
  • 2017-09-30
相关资源
最近更新 更多