Web.Config阻止整个网站

时间:2013-05-14 22:01:39

标签: php wordpress iis web-config restrict

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

我的web.config只处理主页面和root中的任何.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文件。

谢谢

2 个答案:

答案 0 :(得分: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?Redirected=true

它与行preCondition =“”

有关

答案 1 :(得分:0)

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

以下是我的片段; 请注意,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>
相关问题