当前位置:网站首页>State management uses session to restrict page access. Only login can verify sessionlogin Aspx can access session aspx

State management uses session to restrict page access. Only login can verify sessionlogin Aspx can access session aspx

2022-06-29 21:50:00 Eighty eight old

First visit Session Jump to on page SessionLogin page
Session.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="lblMsg" runat="server" ></asp:Label>
        </div>
    </form>
</body>
</html>

Session.aspx.cs

using System;

public partial class Chap2_Session : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
        if(Session["Name"]!=null)
        {
    
            lblMsg.Text = Session["Name"] + ", Welcome !";
        }
        else
        {
    
            Response.Redirect("~/Chap2/SessionLogin.aspx");
        }
    }
}

SessionLogin.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
         user name :<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <br />
         password :<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text=" confirm " OnClick="btnSubmit_Click" />
    </form>
</body>
</html>

SessionLogin.aspx.cs

using System;

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

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    
        // Comparison between the actual project and the data stored in the database 
        if (txtName.Text == "leaf" && txtPassword.Text == "111")
        {
    
            // assignment 
            Session["Name"] = "leaf";

        }
    }
}
原网站

版权声明
本文为[Eighty eight old]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/180/202206292125086287.html

随机推荐