如何限制静态文件从浏览器访问 [英] How to restrict static files to access from browser

查看:138
本文介绍了如何限制静态文件从浏览器访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我一直在努力限制静态文件从浏览器下载。但不能限制。我知道以下代码应该可以正常工作。

这是根web.config文件代码。

 <   location    路径  = 模板 >  
< system.web >
< 授权 >
< deny 用户 = * / > ;
< / authorization >
< / system.web >
< / location >



我在根文件夹的Templates文件夹中提供了一些文档和Excel文件。我想限制所有用户的文件。



可以请任何人帮忙吗?



我尝试了什么:



我在root web.config文件和Templates文件夹web.config文件中使用了以下代码。< br $>


 <   location    路径  = < span class =code-keyword>模板 >  
< system.web >
< 授权 >
< ; deny users = * / >
< / authorization >
< < span class =code-leadattribute> / system.web >
< / location >

解决方案

问题是,ASP.NET服务器在提供静态内容时不会涉及(默认情况下),例如文件夹中的文件...

如果运行时不涉及,没有人会检查web.config文件中的内容...

您有几个选项:

1.将相关文件类型映射到ASP.NET发动机

2.写自定义ha ndler到服务器(在你的情况下为r)这些文件

3.使用IIS 7中的集成管道使所有请求调用ASP.NET运行时...



了解IIS 7.0 URL授权:官方Microsoft IIS站点 [ ^

Hi all,
I have been struggling to restrict static files to download from browsers. But not able to restrict. I know that the following code should work but not working.
This is the root web.config file code.

<location path="Templates">
  <system.web>
    <authorization>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>


I have some documents and excel files available at Templates folder in root folder. I want to restrict the files for all users.

Could any one please help on this?

What I have tried:

I have used the following code in both root web.config file and Templates folder web.config file.

<location path="Templates">
  <system.web>
    <authorization>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>

解决方案

The problem is that ASP.NET runtime do not involved (by default) when serving static content, like files from your folder...
If the runtime not involved, than no-one will check what written in the web.config file...
You have several options:
1. Map relevant file types to the ASP.NET engine
2. Write custom handler to server (r deny in your case) those files
3. Use the integrated pipeline in IIS 7 to make all requests invoke ASP.NET runtime...

Understanding IIS 7.0 URL Authorization : The Official Microsoft IIS Site[^]


这篇关于如何限制静态文件从浏览器访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆