The Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Namespace www
{
Public partial class piaoju1: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
}
// Set the user logon flag and associate it with the browser. The failure condition is that the browser is disabled.
Protected void btnSet_Click (object sender, EventArgs e)
{
System. Web. Security. FormsAuthentication. SetAuthCookie ("uName, uPower", false );
}
// Obtain the user name
Protected void btnGet_Click (object sender, EventArgs e)
{
Response. Write (HttpContext. Current. User. Identity. Name );
}
// Exit
Protected void btnLogout_Click (object sender, EventArgs e)
{
FormsAuthentication. SignOut ();
}
// Determine whether to log on
Protected void btnShow_Click (object sender, EventArgs e)
{
If (HttpContext. Current. User. Identity. IsAuthenticated)
Response. Write ("OK ");
Else
Response. Write ("no ");
}
}
}
The Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "piaoju1.aspx. cs" Inherits = "www. piaoju1" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> simple use of a ticket </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: Button ID = "btnShow" runat = "server" Text = "show" OnClick = "btnShow_Click"/>
<Asp: Button ID = "btnSet" runat = "server" Text = "set" OnClick = "btnSet_Click"/>
<Asp: Button ID = "btnGet" runat = "server" Text = "get" OnClick = "btnGet_Click"/>
<Asp: Button ID = "btnLogout" runat = "server" Text = "out" OnClick = "btnLogout_Click"/>
</Div>
</Form>
</Body>
</Html>