Copy Code code 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 user login flag, associated with browser, failure condition is browser shutdown
protected void Btnset_click (object sender, EventArgs e)
{
System.Web.Security.FormsAuthentication.SetAuthCookie ("Uname,upower", false);
}
Get 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 sign in
protected void Btnshow_click (object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
Response.Write ("OK");
Else
Response.Write ("no");
}
}
}
Copy Code code 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 ">
<title> Simple use of Bills </title>
<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>