加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 00:39:02 所属栏目:asp.Net 来源:网络整理
导读:我是ASP.NET的新手,所以原谅我,如果这很简单。 我试图通过web.config拒绝访问我的“管理”文件夹。我查看了另一个类似问题的答案,他们建议使用 location文件夹,但是当我在路径中插入“Admin /”时,我得到以下错误: path attribute must be a relative
我是ASP.NET的新手,所以原谅我,如果这很简单。

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

path attribute must be a
relative virtual path. It cannot
start with any of ‘ ‘ ‘.’ ‘/’ or
‘’. C:PersonalProjectsOliverSalonweb.config

我试过放置“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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读