Web
<configuration>
<system
<compilation debug="true"/>
<authentication mode="Forms">
<forms loginUrl="login
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system
</configuration>
default
<HTML>
<HEAD>
<TITLE>首頁</TITLE>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object
Message
End Sub
sub btnSignout_Click(Sender as Object
FormsAuthentication
Response
end sub
</script>
</HEAD>
<BODY>
<asp:label id="Message" runat="server"/>
<br>
<form method="post" runat="server">
<asp:button id="btnSignout" Text="退出登錄" runat="server" OnClick="btnSignout_Click"/>
</form>
</BODY>
</HTML>
login
<HEAD>
<TITLE>首頁</TITLE>
<script lanugage="c#" runat="server">
private void Page_Load(object sender
{
if (Request
Response
}
void btnLogin_Click(Object sender
{
if (txtUsername
FormsAuthentication
else
lblError
}
</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>
From:http://tw.wingwit.com/Article/program/net/201311/14178.html