阻止直接访问文件,但允许通过http使用asp.net

时间:2014-02-18 07:08:04

标签: c# asp.net

我正在使用下面的代码来允许在我的Intranet asp.net Web应用程序中下载文件。但是一个用户入侵并找到了该文件的共享文件夹路径。如何限制它?

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ";");
response.TransmitFile(Server.MapPath("FileDownload.pdf"));
response.Flush();
response.End();  

1 个答案:

答案 0 :(得分:0)

您可以使用“目录浏览”选项(IIS 7)在IIS中禁用它:

enter image description here

或者您可以通过更改web.config并添加以下选项来自行完成:

<configuration>
   <system.webServer>
      <directoryBrowse enabled="false" />
   </system.webServer>
</configuration>
相关问题