【发布时间】: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