asp.net - prevent下载特定文件 [英] asp.net - prevent downloading a specific file

查看:117
本文介绍了asp.net - prevent下载特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我也有被保护以查看其在浏览器中的内容是UserFiles目录:

I have a website where I also have a "UserFiles" directory which is protected to view its content in browser:

这虚拟目录不允许列出的内容。

This Virtual Directory does not allow contents to be listed.

问题是,我这里有一些文件,如果您知道文件的名称,例如:

The problem is that I have some files here which, if you know the name of the file, for instance:

http://example.com/UserFiles/file.ppt

您可以下载它。

有什么办法来保护这也从web.config中?或者,如果用户试图访问此,做一个重定向到登录页面?

请注意,我不使用Forms身份验证,但是自定义登录和Windows身份验证为开。

Please note that I do not use Forms authentication but a custom login and Windows authentication is On.

谢谢,

更新:我会尝试一下本作的时刻: HTTP :?//www.dotnetcurry.com/ShowArticle.aspx ID = 270

UPDATE: I will try this for the moment: http://www.dotnetcurry.com/ShowArticle.aspx?ID=270

推荐答案

如果你仍然想通过的web.config 来做到这一点,你的网​​络的.config 文件应该有这个在 HttpHandlers的部分:

If you still want to do this via web.config, your web.config file should have this under the httpHandlers section:

<system.web>
    <httpHandlers>
        <add verb="*" path="*.ppt" type="System.Web.HttpForbiddenHandler" />
    </httpHandlers>
</system.web>

这将阻止所有.PPT文件。

That will block all .ppt files.

这篇关于asp.net - prevent下载特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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