【发布时间】:2013-04-05 15:22:32
【问题描述】:
我目前正在尝试创建自己的 CMS 系统。
在“/tools/default.aspx”页面我有一个登录,成功登录后,重定向到“/tools/cms.aspx”。
我已使用 Windows 身份验证来阻止对文件夹的不必要访问,但如果我在页面“/cms/cms.aspx”中键入,我可以在不登录的情况下访问 CMS。
编辑:
我已阻止访问 CMS,但现在无法登录,我仍然可以访问其文件夹。
/tools/web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="default.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="styles">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="images">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="CMSLogin" loginUrl="~/tools/default.aspx" protection="All" timeout="20" path="/" />
</authentication>
<roleManager enabled="true" />
</system.web>
</configuration>
*删除敏感的 web.config 信息
登录验证尝试:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string passWord = Login1.Password;
bool rememberUserName = Login1.RememberMeSet;
using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["websiteContent"].ConnectionString))
{
sqlCon.Open();
string SQL = "SELECT CMS_Username, CMS_Password FROM CMS_Users WHERE CMS_Username ='" + userName + "' AND CMS_Password ='" + passWord + "'";
using (SqlCommand sqlComm = new SqlCommand(SQL, sqlCon))
{
sqlComm.ExecuteScalar();
if (sqlComm.ExecuteScalar() != null)
{
Response.Redirect("cms.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
sqlCon.Close();
}
}
【问题讨论】:
-
您是否使用
MasterPages或Forms Authentication如何在.config 文件中设置Authentication..? -
另外,当你是
"Re-Inventing the Wheel"时,我也会考虑实现你自己的user password检查Sql Server. Active Directory, ...etc -
您的问题听起来像是您无意中混合了表单身份验证和 Active Directory 身份验证。我还想查看 .config 中的身份验证设置。
-
您能否向我们展示您的 web.config 文件中的授权和身份验证部分?
-
@Penfold 我更新了我的帖子。我想使用表单身份验证,但我也想阻止访问我的 CMS 中的任何内容。