拒绝访问在web.config中“管理”文件夹 [英] Deny access to 'admin' folder in web.config

查看:114
本文介绍了拒绝访问在web.config中“管理”文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来ASP.NET,所以请原谅我,如果这是简单的。

I am new to ASP.NET, so forgive me if this is simple.

我试图拒绝通过的web.config访问我的管理文件夹中。我看着另一个回答类似的问题,他们推荐使用<地点> 文件夹,但是当我插入管理/进入我得到以下错误的路径:

I am trying to deny access to my 'Admin' folder via web.config. I looked at another answer to a similar question and they recommend using the <location> folder, however when I insert "Admin/" into the path I get the following error:

路径属性必须是
  相对虚拟路径。这不可能
  启动与任何''的'。 '/' 要么
  \\。 C:\\个人\\项目\\ OliverSalon \\ web.config中

path attribute must be a relative virtual path. It cannot start with any of ' ' '.' '/' or '\'. C:\Personal\Projects\OliverSalon\web.config

我曾尝试将管理,/管理员&放大器; 管理/

I have tried placing "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表单天回来的路。

This is way back from my web form days.

将一个web.config在你的管理文件夹中。

Place a web.config in your admin folder.

的内容应该是:

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

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

** EDIT to answer your question If you set the login url the framework will automatically send you to the login page if an unauthorized user tries to access your admin folder.

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

这篇关于拒绝访问在web.config中“管理”文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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