繁体   English   中英

拒绝访问web.config中的“admin”文件夹

[英]Deny access to 'admin' folder in web.config

我是ASP.NET新手,如果这很简单,请原谅我。

我试图通过web.config拒绝访问我的'Admin'文件夹。 我查看了类似问题的另一个答案,他们建议使用<location>文件夹,但是当我在路径中插入“Admin /”时,我收到以下错误:

path属性必须是相对虚拟路径。 它不能以任何'''开头。 '/' 要么 '\\'。 C:\\个人\\项目\\ OliverSalon \\的web.config

我试过放置“Admin”,“/ Admin”和“Admin /”

<configuration>

<connectionStrings>
    <add name="OliverSalonConnectionString1" connectionString="Data Source=localhost;Initial Catalog=OliverSalon;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
    <compilation debug="false" targetFramework="4.0" />
    <authentication mode="Forms">
        <forms name="Oliver" loginUrl="Login.aspx" path="/" timeout="20">
            <credentials passwordFormat="Clear">
                <user name="OliverSalon" password="cuts"/>
            </credentials>
        </forms>
    </authentication>
    <authorization >
        <deny users="?"/>
    </authorization>
</system.web>
<location path="/Admin">
    <system.webServer>
        <directoryBrowse enabled="false"/>
    </system.webServer>
</location>

这是从我的网络形式回来的方式。

在您的管理文件夹中放置web.config。

内容应该是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
          <allow roles="admin" />
          <deny users ="*" />
        </authorization>
    </system.web>
</configuration>

**编辑以回答您的问题如果您设置登录URL,如果未经授权的用户尝试访问您的管理文件夹,框架将自动将您发送到登录页面。

        <authentication mode="Forms">
            <forms loginUrl="Login.aspx" timeout="20" slidingExpiration="true" cookieless="AutoDetect" protection="All" requireSSL="false" enableCrossAppRedirects="false" defaultUrl="Default.aspx" path="/"/>
</authentication>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM