asp.net中Session小例子

asp.net中Session小例子登录界面aspx代码如下:functionisempty(){vartxt_id=document.getElementById(“txt_userID”);if(txt_id.value==””){alert(“请输入用户名!”);

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

asp.net中Session小例子

登录界面aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="session_login.aspx.cs" Inherits="session_login" %>

<!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>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function isempty() {
            var txt_id = document.getElementById("txt_userID");
            if (txt_id.value == "") {
                alert("请输入用户名!");
                txt_id.focus();
                return false;
                
            }
            else {return true;}
        
        }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>登录界面</h3>
        <p class ="divTc">
            输入用户名:
            <asp:TextBox ID="txt_userID" runat="server"></asp:TextBox>
        </p>
        <p class="divTc">
            <asp:Button ID="btn_login" runat="server" Text="登录" οnclick="btn_login_Click" OnClientClick="return isempty()" />
        </p>
    </div>
    </form>
</body>
</html>

登录.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class session_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        Session["uid"] = txt_userID.Text;
        Server.Transfer("session_check.aspx");
    }
}

读取.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="session_check.aspx.cs" Inherits="session_check" %>

<!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>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
       
        <asp:Button ID="Button1" runat="server" Text="退出登录" οnclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

读取.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class session_check : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] != null)
        {
            string _id = Session["uid"].ToString();
            Label1.Text = "欢迎登录," + _id + "!";
        }
        else {
            Response.Redirect("session_login.aspx");
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session.Remove("uid");
        
        //跳转到本身看看
        Server.Transfer(Request.Url.LocalPath.ToString());

    }
}


asp.net中Session小例子
asp.net中Session小例子

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159514.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 免费且超级好用的搜索引擎INSO[通俗易懂]

    免费且超级好用的搜索引擎INSO[通俗易懂]免费且超级好用的搜索引擎INSO已经上线啦,界面UI是采用FlatUI设计,能够搜索到很多很多资源,近期资源一般来说要等10天左右,否则基本上是枪版。后面我会推出开发这个搜索引擎的系列教程的,尽请期待!网址是http://www.inso.hk

    2022年7月18日
    28
  • 将python打包成exe_python程序打包成安装包

    将python打包成exe_python程序打包成安装包Python Windows下打包成exe文件

    2022年4月21日
    55
  • php数组转换对象方法[通俗易懂]

    php数组转换对象方法[通俗易懂]php虽然不能像js那样直接newObject,但php支持匿名类我们直接新建匿名类进行转换就好了 /***数组转对象*@paramArray$array*@authorQuan*@returnObject*/protectedfunctionarrayTransitionObject(Arr…

    2022年9月11日
    1
  • Odin Inspector 系列教程 — Custom Value Drawer Attribute

    Odin Inspector 系列教程 — Custom Value Drawer AttributeCustomValueDrawerAttribute特性,允许用户自定义一个绘制方法,字段将以自定的绘制方式展示在Inspector中,非常灵活。含有Label和不含有Label的字段[CustomValueDrawer(“HaveLabelNameFunction”)]publicstringHaveLabelName;…

    2022年7月21日
    12
  • Vue router2.0

    Vue router2.0对于单页面来说路由是我们常用切换页面的一种方式,使用Vue安装npminstallvue-router–save路由的引入importrouterfrom’./router’/*eslint-disableno-new*/newVue({el:’#app’,store,router,components:{App},template:'<App/>’})路由的配置通过和也可以实现我们像a标签一样

    2022年7月11日
    18
  • 8.WLAN频段介绍_频段与信道「建议收藏」

    8.WLAN频段介绍_频段与信道「建议收藏」频段与信道1、ISM频段一、pandas是什么?二、使用步骤1.引入库2.读入数据总结1、ISM频段一、pandas是什么?示例:pandas是基于NumPy的一种工具,该工具是为了解决数据分析任务而创建的。二、使用步骤1.引入库代码如下(示例):importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportseabornassnsimportwarningswarnings.fil

    2022年10月9日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号