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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 百度云网页视频加速播放

    百度云网页视频加速播放最近使用百度云看考研视频,但是百度云的播放器太简陋,无法倍速播放视频,太浪费时间了,听说firefox可以加速播放,可我又是chrome的死忠,于是在网上查到一个简单的方法。进入播放页面,按F12进入开发者模式在console中输入:videojs.getPlayers(&quot;video-player&quot;).html5player.tech_.setPlaybackRate(2…

    2022年5月24日
    39
  • acwing1098. 城堡问题(bfs宽搜)「建议收藏」

    acwing1098. 城堡问题(bfs宽搜)「建议收藏」1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####—#####—#—#####—# 2 # # | # # # # # #—#####—#####—#####—# 3 # | | # # # # # #—#########—#####–…

    2022年8月9日
    5
  • PyCharm Flask框架安装

    PyCharm Flask框架安装打开命名行窗口 执行下面命令 pipinstallfl pipinstallfl login pipinstallfl openid pipinstallfl sqlalchemy pipinstallsq migrate pipinstallfl whooshalche

    2025年8月31日
    2
  • 学习zencart模板制作[通俗易懂]

    学习zencart模板制作[通俗易懂]

         
        1,在includes/template下面新建个文件夹叫你新
    模板的名字就可以了(名字可以随便给只要你自己知道就
    可以了)这里我就叫yourname
        2,把includes/template/defalut_template
           这个文件夹下面的所有的文件夹和文件复制到你
    刚刚新建的文件夹里面去yourname
        3,把template_info.p

    2022年7月27日
    5
  • PHP 函数之 call_user_func &amp; call_user_func_array[通俗易懂]

    PHP 函数之 call_user_func &amp; call_user_func_array

    2022年2月5日
    47
  • java8 小技巧保证分组groupingBy后排序不变

    java8 小技巧保证分组groupingBy后排序不变问题:遇到一个小问题,查询出来一组数据后,按照其中的属性进行groupBy分组,分组后要保证顺序不变。排查首先去api中查找解决//一个参数publicstatic<T,K>Collector<T,?,Map<K,List<T>>>groupingBy(Function<?superT,?ex…

    2022年8月21日
    10

发表回复

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

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