CopyCode 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 ");
}
}
}
Copy codeThe 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>