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

Jon*_*ing 19 asp.net security

我是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>
Run Code Online (Sandbox Code Playgroud)

san*_*oIT 24

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

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

内容应该是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
          <allow roles="admin" />
          <deny users ="*" />
        </authorization>
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

**编辑以回答您的问题如果您设置登录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>
Run Code Online (Sandbox Code Playgroud)