Web.config
復制代碼 代碼如下:
default.aspx
login.aspx
<HEAD>
<TITLE>首頁</TITLE>
<script lanugage="c#" runat="server">
private void Page_Load(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
Response.Redirect("default.aspx");
}
void btnLogin_Click(Object sender, EventArgs e)
{
if (txtUsername.Text != null && txtUsername.Text != String.Empty && txtPassword.Text != null && txtPassword.Text != String.Empty)
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
else
lblError.Text = "錯誤的用戶名/密碼";
}
</script>
</HEAD>
<BODY>
<form method="post" runat="server">
<asp:Label id="lblUsername" runat="server" Text="用戶名:"/>
<asp:Textbox id="txtUsername" runat="server"/>
<br>
<br>
<asp:Label id="lblPassword" runat="server" Text="密 碼:"/>
<asp:Textbox id="txtPassword" runat="server" TextMode="password"/>
<br>
<asp:button id="btnLogin" runat="server" Text="登錄" OnClick="btnLogin_Click" />
</form>
<hr>
<br>
<asp:Label id="lblError" forecolor="red" runat="server"/>
</BODY>
</HTML>