ASP.net web自带安全机制
Web.config配置
<configuration>
<location path="defalut.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
<location path="Cinema3D">
<system.web>
<authorization>
<deny users="2D"/>
</authorization>
</system.web>
</location>
<location path="student">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<system.web>
<authentication mode="Forms">
<forms name="test" loginUrl="index.aspx" defaultUrl="defalut.aspx" cookieless="AutoDetect"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
index
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DDLticket" runat="server">
<asp:ListItem>3D</asp:ListItem>
<asp:ListItem>2D</asp:ListItem>
<asp:ListItem>学生区</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="tbMoney" runat="server"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" Text="Button" onclick="btnGo_Click" />
</div>
</form>
</body>
</html>
//cs类
protected void btnGo_Click(object sender, EventArgs e)
{
if (this.DDLticket.Text == "2D") {
if (int.Parse(this.tbMoney.Text) >= 30 ) {
FormsAuthentication.RedirectFromLoginPage("2D", false);
}
}
if (this.DDLticket.Text == "3D") {
if (int.Parse(this.tbMoney.Text) >= 70)
{
FormsAuthentication.RedirectFromLoginPage("3D", false);
}
}
if (this.DDLticket.Text == "学生区") { }
}