我一直致力于一个网站项目,该项目限制对匿名用户访问某个文件夹,并允许访问该文件夹给那些登录的人。 这一直在我的开发机器上完美运行。
但是,自从发布网站并部署到Web服务器(Windows Server 2008,IIS7)后,表单身份验证似乎无法正常工作。匿名用户可以访问“受限”文件夹。 我比较了开发机器和Web服务器上的 webconfig ,它们完全相同。
我使用此tutorial使用.NET Framework中内置的网站管理工具设置对开发计算机上目录的访问/限制。但是我知道这个工具只是localhost吗?
请注意:我没有使用asp.net登录和注册控件。我在后面的代码中使用自定义函数(C#)
这个问题是由位置变化引起的吗? 开发计算机目录: C:\ Users \ Megatron \ Documents \ Visual Studio 2010 \ Projects \ Osqar - v0.2 \ OSQARv0.1 Web服务器目录: C:\ inetpub \ wwwroot \ Osqar
我有点迷失在这里,所以任何建议都会非常感激。
这是网络配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="dbConn" connectionString="data source=mssql.database.com; Initial Catalog=devworks_oscar;User ID=myusername;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms name="Osqar" loginUrl="/login/login.aspx" protection="All" path="/" timeout="60" />
</authentication>
<compilation debug="true" />
<pages /></system.web>
<system.webServer>
<defaultDocument>
<files>
<add value="index.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
答案 0 :(得分:2)
authorization
部分似乎缺失(?)。你应该有像
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
如果没有关于所需授权级别的信息(拒绝匿名用户),应用程序服务器将让每个人都去任何地方。
答案 1 :(得分:1)
将其放在<cofiguraation>
主标记下:
<configuration>
<location path="~/RestrictedFolder">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
....
如果您限制特定文件,请执行以下操作:
<location path="~/securedpage.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
对已部署项目中的web.config执行这些更改
另外,Wiktor建议用来阻止对整个网站的匿名访问
可能在<system.web>
代码
<authentication>
之下
<authorization>
<deny users="?"/>
</authorization>
或者在项目的根目录下创建一个文件夹,并将安全页面放在该文件夹中。 R-单击文件夹添加新的web.config文件,并将以下内容放在<system.web>
标记
<authorization>
<deny users="?"/>
</authorization>