我已經在IIS7上部署了一個Web應用程序,並且該應用程序的郵件附件文件保存在網絡服務器的Attachments
文件夾中,並且在從 應用程序下載附件時它工作正常。如何防止直接訪問asp.net中的文件和文件夾?
問題是,從Chrome瀏覽器中查看相同的網址是從另一臺機器上輸入的,同樣可以查看/下載。 Google搜索後,我嘗試了幾個解決方案,但這裏的網絡服務器上的附件文件夾爲網絡服務啓用了安全性。
http://machine-121/AdminManagement/Attachments/58501/17112014131251/FilledForm.pdf
(可讀取)
我試圖
<configuration>
<system.web>
<authentication mode="Forms"/>
<authorization>
<deny users="?"/> <!--This will restrict anonymous user access-->
</authorization>
</system.web>
<location path="login.aspx"> <!-- Path of your Registration.aspx page -->
<system.web>
<authorization>
<allow users="*"/> <!-- This will allow users to access to everyone to Registeration.aspx-->
</authorization>
</system.web>
</location>
</configuration>
但未能得逞任何建議/幫助將是很大的幫助。
我不會直接公開這些文件。我希望所有的請求都通過一箇中心函數,它需要用戶名和文件名(ID?)並確定他們是否應該能夠獲取文件。如果是這樣,只需使用Repsonse直接發送文件 - 不直接使用鏈接。 –
嗨瑞安,Appriciate,如果你可以指向一些相同的參考鏈接。 – Harry
你想使用像web.cofig中的「請求過濾」。如果是的話,請在這個問題中檢查user1160006的底部答案:http://stackoverflow.com/questions/6822173/denying-direct-access-to-a-folder-only-allow-through-app-answer-20359486。 –