【问题标题】:Web.Config to block entire websiteWeb.Config 阻止整个网站
【发布时间】:2013-05-14 22:01:38
【问题描述】:

我现在有一个登录系统,可以阻止所有未经身份验证的用户查看我的网站内容。我可以确认登录有效。 然而,我现在面临的问题是我的 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 文件。

谢谢

【问题讨论】:

  • 作为更新。似乎我对 system.web 与 system.webserver 行感到困惑。由于我正在运行 IIS7,我应该将验证放在配置的网络服务器部分。

标签: php wordpress iis web-config restrict


【解决方案1】:

因此,正如我评论的那样,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=""

行有关

【讨论】:

    【解决方案2】:

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

    这是我的sn-ps; 注意 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>
    

    【讨论】:

    • 您好史蒂夫,谢谢您的回复。不幸的是,我不相信您的回复是我想要的,或者我不确定如何实施它。例如,index.php 文件位于根目录。如果我设置 并阻止匿名用户访问那里,他们仍然可以出于某种原因。
    • 我建议将您的 loginURL 更改为登录页面的相对路径,这是我怀疑的主要问题,并拒绝来自整个站点的匿名用户。删除您允许的角色,直到您为任何经过身份验证的人工作。
    • 好的,如果可行,我会试一试并发布。我之前应该提到登录页面不在 Wordpress 页面上。如果您尝试访问 Wordpress 页面,它应该重定向到您可以登录的不同 URL,然后 cookie 允许您返回到 Wordpress 页面。
    猜你喜欢
    • 2019-09-10
    • 2012-02-24
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多