如何限制用户访问Asp.net中的XML或图像 [英] How To Restrict User to Access XML or Images in Asp.net

查看:49
本文介绍了如何限制用户访问Asp.net中的XML或图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

I want to Restrict to Access Images and XML folder to ALL,


Ex : if any one Type

http://www.Sample.com/Images/Banner.jpg or

http://www.Sample.com/XML/test.XML

User Should be Redirect to Login Page ,

I tried By Using

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

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

 </authorization>
 </system.web>
 </location>


in Login Page or any other page , It's Blocking Images in Page ...

Any One Help Me Out

推荐答案

您好,



您可以添加
Hello,

You can add
<authorization />

到根web.config,例如:

to the root web.config, like:

<location path="Admin">
    <system.web>
        <authorization>
            <allow roles="Administrator"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>



或者您可以使用以下内容将web.config添加到要允许/拒绝访问的文件夹中:


or you can add a web.config to the folder where you want to allow/deny access with the following content:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <authorization>
            <allow roles="Administrator"/>
            <deny users="*" />
        </authorization>
    </system.web>
</configuration>



当然要替换


Of course replace the

<allow />

<deny />

拥有自己的规则;)


这篇关于如何限制用户访问Asp.net中的XML或图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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