1

我目前有一个登录系统,可以阻止所有未经身份验证的用户查看我的网站内容。我可以确认登录有效。然而,我现在面临的问题是我的 web.config 文件。我能够阻止未经验证的用户查看主页(即 www.mysite.com),这反过来会加载 index.php。用户仍然可以访问 www.mysite.com/index.php 而无需登录,这会破坏登录的目的。

我的 web.config 只处理主页和根目录中的任何 .aspx 文件。下面是我的 web.config 代码。我已经寻找了一段时间的解决方案,但还没有找到让 web.config 为整​​个站点工作的方法。此外,它位于根目录(我的网站使用 wordpress)。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>

    <compilation defaultLanguage="c#" debug="false" />
    <customErrors mode="Off" /> 
    <authentication mode="Forms"> 
        <forms
            name=".myCookie"
            loginUrl="http://www.mysite.com"
            domain="mysite.com"
            protection="All"
            timeout="120"
            path="/"
            requireSSL="false"
            slidingExpiration="true"
        />
    </authentication>

 <authorization>
          <allow roles="AA,BB" />
          <deny users="*" />
      </authorization>

    <machineKey
        validationKey="xxxxxxx"
        decryptionKey="xxxxxxx"
        validation="SHA1"
    />
    <sessionState mode="Off" /> 
</system.web>

<system.webServer>
<defaultDocument>
        <files>
            <add value="index.php" />
        </files>
    </defaultDocument>
<rewrite>
  <rules>
    <rule name="wordpress" patternSyntax="Wildcard">
        <match url="*" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php" />
    </rule>
</rules>
 </rewrite>
 </system.webServer>

</configuration>

任何帮助将不胜感激,因为我在这方面花了很长时间,我觉得它应该是一个简单的解决方案。我也在运行 IIS 7。

总结一下我的问题,我需要 web.config 文件来阻止对所有类型的文件(php、.txt 等)的访问,而不仅仅是根 URL 和 .aspx 文件。

谢谢

4

2 回答 2

2

因此,正如我评论的那样,system.web 用于 iis6,而 system.webServer 用于 iis7,这是我正在运行的。我对 system.web 的授权规则是正确的,因此任何 .net 文件都按预期被阻止,但是由于 iis7 管道集成,任何其他文件扩展名都不会受到影响。我从以下网址找到了解决方案:http: //blogs.msdn.com/b/rakkimk/archive/2007/11/28/iis7-making-forms-authentication-to-work-for-all-the-requests。 aspx?重定向=真

它与 preCondition="" 行有关

于 2013-05-15T21:15:33.353 回答
0

通常,除非您在 web.config 中使用“位置”标签,否则安全性将对整个站点生效。

这是我的片段; 注意 loginURL 是一个特定的页面

<authentication mode="Forms">
  <forms loginUrl="~/public/Login.aspx" slidingExpiration="true" timeout="45" />
</authentication>
<authorization>
  <deny users="?"/>
</authorization>

这 ?代表匿名用户 事实上,要让 css 正常工作,您必须添加以下授权每个人访问这些文件:

<!-- Allow Anonymous Access to the Themes Folder -->
<location path="App_Themes" >
<system.web>
  <authorization>
    <allow users="*" />
  </authorization>
</system.web>
</location>
于 2013-05-14T22:09:21.070 回答