How to Prevent direct access to files and folders in asp.net?

前端 未结 4 1447

I have deployed a web application on IIS7 and the application has mail attachment files saved on webserver\'s Attachments folder and it\'s working fine when the

4条回答
  •  [愿得一人]
    2020-12-12 04:39

    The problem is that the .pdf extension isn't caught by the ASP.NET handlers, since that isn't a file type that is mapped to ASPNET_ISAPI (aka the ASP.NET HTTP Runtime). Hence the filtering in your web.config file doesn't apply to those files.

    You have two options:

    1. Map all file extensions (or at least pdf files in this case) to ASPNET_ISAPI using the IIS configuration panel. Note that this will increase the load on your server since the overhead of IIS on itself is lower than IIS + ASP.NET;
    2. Use an HTTP handler that gets the file for you. This allows you to do some fine grained authorization checks on the file access too. See the Introduction to HTTP Handlers.

提交回复
热议问题