使用web.config密码保护文件夹

hes*_*bom 8 asp.net web-config

我必须用密码保护Windows服务器上的目录.该页面应该显示该目录中的文件列表.我之前没有任何知识(之前只与Apache合作过),所以我试图通过谷歌搜索一起攻击.(对于那些知道自己在做什么的人,我确信这看起来很荒谬)

我现在拥有的是一个登录弹出窗口,但没有密码正常工作.我们的SQL数据库中有一个用于adminusers的表,所以要么从那里获取用户登录,要么在配置文件中嵌入登录就可以了.我需要的只是受密码保护的文件夹.

这就是我现在在我的web.config文件中所拥有的文件,该文件位于应该受密码保护的文件夹中.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <authentication mode="Forms">
            <credentials passwordFormat="Clear">
                <user name="test" password="test" />
            </credentials>
        </authentication>
        <authorization>
            <allow users="test" />
            <deny users="*" />
        </authorization>
    </system.web>
    <system.webServer>
        <directoryBrowse enabled="true" />
        <security>
            <authentication>
                <anonymousAuthentication enabled="false" />
                <basicAuthentication enabled="true" />
                <windowsAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

希望这是一个简单的问题,并提前感谢任何帮助!:)

Jam*_*son 6

尝试这个:

<configuration>      
    <system.web>      
        <authentication mode="Forms">      
            <credentials passwordFormat="Clear">      
                <user name="test" password="test" />      
            </credentials>      
        </authentication>      
        <authorization>      
            <allow users="test" />      
            <deny users="*" />      
        </authorization>      
    </system.web>      
    <location path="admin">
        <system.web>
            <authorization>              
                <allow roles="admin" />
                <deny users="*"/>
            </authorization>
        </system.web>
    </location> 
    <system.webServer>      
        <directoryBrowse enabled="true" />      
        <security>      
            <authentication>      
                <anonymousAuthentication enabled="false" />      
                <basicAuthentication enabled="true" />      
                <windowsAuthentication enabled="false" />      
            </authentication>      
        </security>      
    </system.webServer>      
</configuration>
Run Code Online (Sandbox Code Playgroud)

您可以使用以下方法加密用户信息:

aspnet_regiis.exe -pef "sectionName" C:\Path\To\Your\Application
Run Code Online (Sandbox Code Playgroud)

  • @JamesJohnson 它提示输入用户名并通过,但是当我分别为用户名和密码提供 `test` 和 `test` 时,我不会验证并继续提示 (2认同)