欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net 票据简单应用

程序员文章站 2024-03-11 22:02:43
复制代码 代码如下:using system; using system.data; using system.configuration; using system.co...
复制代码 代码如下:

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)
{

}
//设置用户登录标志,与浏览器关联,失效条件是浏览器关闭
protected void btnset_click(object sender, eventargs e)
{
system.web.security.formsauthentication.setauthcookie("uname,upower", false);
}
//取得用户名
protected void btnget_click(object sender, eventargs e)
{
response.write(httpcontext.current.user.identity.name);
}
//退出
protected void btnlogout_click(object sender, eventargs e)
{
formsauthentication.signout();
}
//判断是否登录
protected void btnshow_click(object sender, eventargs e)
{
if (httpcontext.current.user.identity.isauthenticated)
response.write("ok");
else
response.write("no");
}
}
}

复制代码 代码如下:

<%@ 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>票据的简单使用</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>