我正在使用表单身份验证及其工作正常。但是在 user1 登录后,他将显示 user1.aspx 页面,但如果他在登录后更改 url,他可以访问 user2 页面,这也不应该发生,所以我在 web config 文件中进行了更改像这样
<authentication mode="Forms">
<forms
name=".LOGIN"
cookieless="UseCookies"
loginUrl="LOGIN.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="~/CabScheduler/User1/User1.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="~/CabScheduler/User2/User2.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
在登录页面——
protected void btnLogin_Click(object sender, EventArgs e)
{
bool validLogin = false;
validLogin = IsValidUser(txtUserName.Text.Trim(), txtPassword.Text.Trim());
int UserId = FindRoleId(txtUserName.Text.Trim(), txtPassword.Text.Trim());
if (validLogin)
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text.Trim(), false);
if(UserId ==1)
Response.Redirect("~/User1/User1.aspx");
else
Response.Redirect("~/User2/User2.aspx");
}
else
lblInformation.Text = "Incorrect Login Information";
}
告诉我我错过了什么或做错了什么。非常感谢!