Asp.net 使用web.config对文件夹进行密码保护

Asp.net 使用web.config对文件夹进行密码保护,asp.net,web-config,Asp.net,Web Config,我必须对Windows服务器上的目录进行密码保护。该页面应该显示位于该目录中的文件列表。我没有任何以前的知识(以前只与Apache合作过),所以我尝试通过谷歌搜索来破解一些东西。(对于知道自己在做什么的人来说,我相信这看起来很可笑) 我现在得到的是一个登录弹出窗口,但没有密码工作。我们的SQL数据库中有一个用于adminusers的表,因此从那里获取用户登录名或将登录名嵌入配置文件都可以。所有我需要的是文件夹要密码保护 <?xml version="1.0" encoding="UTF-8

我必须对Windows服务器上的目录进行密码保护。该页面应该显示位于该目录中的文件列表。我没有任何以前的知识(以前只与Apache合作过),所以我尝试通过谷歌搜索来破解一些东西。(对于知道自己在做什么的人来说,我相信这看起来很可笑)

我现在得到的是一个登录弹出窗口,但没有密码工作。我们的SQL数据库中有一个用于adminusers的表,因此从那里获取用户登录名或将登录名嵌入配置文件都可以。所有我需要的是文件夹要密码保护

<?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>
这就是我现在在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>

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

试试这个:

<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>

您可以混合使用基本身份验证和表单身份验证。如果您希望test/test在弹出窗口中工作,则不会。基本身份验证需要服务器上的windows用户名/密码。您要么需要走这条路,要么放弃基本的身份验证,实现FormsAuthentication:登录页面等的其余部分。您认为仍然可以使用会话等进行“自定义”登录并使用“directoryBrowse”吗?是否可以以某种方式使用弹出窗口作为登录而不是表单?我将把它放在哪里?在根目录上的配置文件中,还是在我在问题中提到的配置文件中?从何处获取用户信息?将其放入web.config文件中,在system.web部分之外。@JamesJohnson它会提示输入用户名和密码,但当我分别为用户名和密码提供
test
test
时,我会进行验证并继续prompting@JamesJohnson我想在Windows Server 2008R2的根目录上输入密码,IIS管理员抱怨它不知道该节点“凭证”