且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们如何防止Filels(docx或jpg)通过地址栏(URL)直接访问

更新时间:2023-12-01 15:30:40

如果您使用的是.Net,请使用global.asax并在global.asax文件中的以下文件后面使用以下代码

if you are using .Net use global.asax and use below code in your global.asax code behind file

Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
    '' Fires right before the request handler executes
    ''Files is folder in the  file path
    If Context.Request.Url.AbsoluteUri.IndexOf("/Files/") > 0 Then
        If Context.Request.Url.AbsoluteUri.IndexOf(".doc") > 0 Then
            Context.Response.End()
        End If
    End If
End Sub