.net框架和c#程序设计第二次测试

一、实验内容

1、设计一个用户登录页面webform1.aspx,效果如下图所示:

2、点击webform1.aspx中“还未注册”连接进入register.aspx,注册页面效果如下图所示:点击用户注册信息到usershow.aspx页面,并显示注册的用户信息。

3、用户分别使用admin和user账户登录系统,分别进入admin.aspx和user.aspx页面,并采用session方法设计权限控制,避免用户通过链接直接访问admin.aspx与user.aspx页面。

4、点击webform1.aspx页面中“记住我”复选框,实现用户免登录功能。如将“记住我”复选框修改为如下图所示,修改并实现其功能。

二、代码实现 

        这是个实验,我就一节课,做了一点点内容,就暂时存一下我目前的进度,对于session和cookie相关的知识点我还是不太能正确使用,所以在重新学习一遍之后,再继续完善题目的要求吧。目前的内容代码如下:

webform1.aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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>
    <link  rel="stylesheet" href="StyleSheet1.css"/>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
            height: 80px;
        }
        .auto-style2 {
            width: 494px;
        }
        .auto-style3 {
            margin-left: 0px;
        }
        .auto-style4 {
            height: 403px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <br />
            <div id="login">
                <div id="top" class="auto-style4"><h1>&nbsp;</h1>
                    <h1>用户登录</h1>
                    <p>&nbsp;</p>
                    <table class="auto-style1">
                        <tr>
                            <td class="auto-style2">
                                <asp:TextBox ID="TextBox1" runat="server" CssClass="txt1" ForeColor="Silver">用户名</asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td class="auto-style2">
                                <asp:TextBox ID="TextBox2" runat="server" CssClass="txt1" ForeColor="Silver">密码</asp:TextBox>
                            </td>
                        </tr>
                    </table>
                    <p>&nbsp;</p>
                    <p>
                        <asp:CheckBox ID="CheckBox1" runat="server" CssClass="txt1" Text="记住我" OnCheckedChanged="CheckBox1_CheckedChanged" />
                    </p>
                    <p>
                        <asp:Button ID="Button1" runat="server" CssClass="auto-style3" Height="50px" OnClick="Button1_Click" Text="登录" Width="210px" BackColor="#337AB7" />
                    </p>
                    <p>&nbsp;
                        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">还未注册</asp:LinkButton>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server">忘记密码</asp:LinkButton>
                    </p>
                    <br />
                    <br />
                </div>

            </div>
        </div>
    </form>
</body>
</html>

stylesheet1.css代码

body {
    margin: 80px auto;
    background-color: #9CBE74;
}
#login{
    background-color:white;
    height:500px;
    width:500px;
    border:1px solid black;
    margin:auto;

}
#login table{
    height:90px;
    width:500px;
    margin:auto;

}
#top {
    height: 400px;
    width: 500px;
    text-align: center;
    margin:auto;
}

.txt1{
    height:40px;
    width:350px;
}

webform1.aspx.cs代码

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

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

        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("register.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == "admin" && TextBox2.Text == "123")
            {
                Session["user"] = "admin";
                Response.Redirect("admin.aspx");
            }
            else if (TextBox1.Text == "User" && TextBox2.Text == "1234")
            {
                Session["user"] = "User";
                Response.Redirect("user.aspx");
            }
            else
            {
                Response.Write("<script>alert('账号或密码错误');</script>");
            }
        }
    }
}

register.aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="WebApplication2.register" %>

<!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>
    <link rel="stylesheet" href="StyleSheet2.css"/>
    <style type="text/css">
        .auto-style1 {
            width: 80%;
            height: 150px;
        }
        .auto-style4 {
            width: 100%;
        }
        .auto-style5 {
            width: 141px;
        }
        .auto-style6 {
            width: 141px;
            height: 60px;
        }
        .auto-style7 {
            height: 60px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server" method="post" action="usershow.aspx">
        <div>
            <div id="login2">
                <h1>&nbsp;</h1>
                <h1>用户注册页面</h1>
                <hr />
                <div id="xinxi">
                    <br />
                    <table class="auto-style1">
                        <tr>
                            <td colspan="1">
                                <table class="auto-style4">
                                    <tr>
                                        <td class="auto-style6">用户名</td>
                                        <td class="auto-style7">
                                            <asp:TextBox ID="TextBox6" runat="server" CssClass="txt" ForeColor="Silver">请输入用户名</asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="auto-style5">密码</td>
                                        <td>
                                            <asp:TextBox ID="TextBox7" runat="server" CssClass="txt" ForeColor="Silver">请输入密码</asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="auto-style5">确认</td>
                                        <td>
                                            <asp:TextBox ID="TextBox8" runat="server" CssClass="txt" ForeColor="Silver">请再次输入密码</asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="auto-style5">姓名</td>
                                        <td>
                                            <asp:TextBox ID="TextBox9" runat="server" CssClass="txt" ForeColor="Silver">请输入真实姓名</asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="auto-style5">邮箱</td>
                                        <td>
                                            <asp:TextBox ID="TextBox10" runat="server" CssClass="txt" ForeColor="Silver">请输入电子邮箱</asp:TextBox>
                                    </tr>
                                </table>
                                <br />
                                <asp:Button ID="Button1" runat="server" Height="44px"  Text="提交注册" Width="125px" />
                            </td>
                        </tr>
                    </table>
                </div>

            </div>
        </div>
    </form>
</body>
</html>

register.aspx.cs代码

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

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("usershow.aspx");
        }


    }
}

stylesheet2.css代码

body {
    background-color:darkgray;
}
#login2{
    background-color:white;
    height:550px;
    width:600px;
    border:1px solid black;
    margin:30px auto;
    text-align:center;
}
    #login2 h1 {
        color:cornflowerblue;
    }
    #login2 hr {
        height: 2px;
        width: 580px;
        margin: auto;
        color: cornflowerblue;
    }
#login2 table{
    margin:0px auto;
    height:250px;
    width:500px;
}
.txt {
    height: 20px;
    width: 300px;
}

usershow.aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="usershow.aspx.cs" Inherits="WebApplication2.usershow" %>

<!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>
            <br />
            所要注册的用户信息<br />
            <br />
            <br />
            用户名:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            密码:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            确认密码:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            姓名:<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            邮箱:<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
        </div>
    </form>
</body>
</html>

usershow.aspx.cs代码:(注意:这里使用的是request的post方法,所以需要在register.aspx源代码中添加相应的代码:

)

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

namespace WebApplication2
{
    public partial class usershow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Request.Form["TextBox6"];
            Label2.Text = Request.Form["TextBox7"];
            Label3.Text = Request.Form["TextBox8"];
            Label4.Text = Request.Form["TextBox9"];
            Label5.Text = Request.Form["TextBox10"];
        }
    }
}

然后就是新建了两个网页admin.aspx和user.aspx,但是里面的内容只有一句话,所以就不贴出来了,后面完善之后再贴。

三、完成结果演示

当随便输入用户名和密码时:

会出现一个弹窗,输出账号或密码错误:

当输入用户名为admin,密码为123时,则会进入admin页面:

 用户名为user,而密码为1234时,进入user界面:

当点击还未注册,则进入注册页面:(这里缺少注册信息的限制,以及相应的验证控件)

提交注册之后,会显示当前需要注册的用户信息:

暂时就完成了这些内容。后面继续补充吧。

        虽然感觉自己整节课都很忙,但是这么总结一下,感觉也没有做出来多少东西,就只是模模糊糊的完成了前三个要求,后面的cookie我刚才尝试了一下,无法得到要求,所以再学习一下再补充吧。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/517418.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

线上研讨会 | 应对汽车毫米波雷达设计中的电磁挑战

智能汽车、新能源汽车最近几年一直是汽车行业关注的热点&#xff0c;随着5G技术越来越普及&#xff0c;汽车智能化发展将越来越迅速。从传统汽车到智能汽车&#xff0c;不是简单功能的增强&#xff0c;而是从单一功能的交通工具变成可移动的办公和娱乐空间&#xff0c;成为物联…

MacOS Docker 部署 Redis 数据库

一、简介 Redis是一个开源的、使用C语言编写的、基于内存亦可持久化的Key-Value数据库&#xff0c;它提供了多种语言的API&#xff0c;并支持网络交互。Redis的数据存储在内存中&#xff0c;因此其读写速度非常快&#xff0c;每秒可以处理超过10万次读写操作&#xff0c;是已知…

GD32F470_MQ-2烟雾检测传感器模块移植

2.5 MQ-2烟雾检测传感器 MQ-2型烟雾传感器属于二氧化锡半导体气敏材料&#xff0c;属于表面离子式N型半导体。处于200~3000摄氏度时&#xff0c;二氧化锡表面吸附空气中的氧&#xff0c;形成氧的负离子吸附&#xff0c;使半导体中的电子密度减少&#xff0c;从而使其电阻值增加…

模板匹配——基于模板与基于特征的两种模板匹配对比

概述 在人工智能&#xff08;AI&#xff09;的研究领域中&#xff0c;模板匹配不仅是一个重要的研究课题&#xff0c;也是解决图像处理中核心问题——定位兴趣区域的关键方法之一。通过模板匹配&#xff0c;可以准确地识别和定位给定图像中的特定对象。这项技术在对象检测、跟…

【Week-Y4】修改yolov5s中C3模块的结构,common.py文件解读

修改C3模块的结构 一、commom.py文件解析二、修改代码&#xff0c;运行train.py训练 &#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 | 接辅导、项目定制 &#x1f4d5;本次任务&#xff1a;将yolov5s网络模型…

Dynamo之雪花分形(衍生式设计)

你好&#xff0c;这里是BIM的乐趣&#xff0c;我是九哥~ 今天简单分享一些我收集的Dynamo的雪花分形案例吧&#xff0c;不过多讲解了&#xff0c;有兴趣的小伙伴&#xff0c;可以私信“雪花分形”获取案例文件&#xff0c;下面基本以分享为主&#xff1a; ******多图预警****…

第四百四十二回

文章目录 1. 概念介绍2. 使用方法2.1 获取思路2.2 获取方法 3. 示例代码4. 内容总结 我们在上一章回中介绍了"如何获取屏幕相关参数"相关的内容&#xff0c;本章回中将介绍如何获取AppBar的高度.闲话休提&#xff0c;让我们一起Talk Flutter吧。 1. 概念介绍 我们在…

文章解读与仿真程序复现思路——电网技术EI\CSCD\北大核心《含储能接入的三相配电网分布式可再生能源可调度域建模与计算》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

糟糕,Oracle归档满RMAN进不去,CPU98%了!

&#x1f4e2;&#x1f4e2;&#x1f4e2;&#x1f4e3;&#x1f4e3;&#x1f4e3; 哈喽&#xff01;大家好&#xff0c;我是【IT邦德】&#xff0c;江湖人称jeames007&#xff0c;10余年DBA及大数据工作经验 一位上进心十足的【大数据领域博主】&#xff01;&#x1f61c;&am…

程序员延寿指南:科学延寿 20 年 | 开源日报 No.214

geekan/HowToLiveLonger Stars: 28.7k License: Unlicense HowToLiveLonger 是一个程序员延寿指南项目。 该项目旨在提供关于如何延长寿命的指南&#xff0c;特别是针对程序员群体。该项目包括术语、目标、关键结果、分析、行动和证据等内容&#xff0c;涵盖了各种与健康相关的…

C语言要点细细梳理——番外:运算符优先级

C语言中的运算符优先级决定了在没有括号的情况下&#xff0c;表达式中的各个部分应如何求值。这个优先级是固定的&#xff0c;并且遵循一定的规则。当运算符的优先级相同时&#xff0c;运算的方向&#xff08;从左到右或从右到左&#xff09;则称为运算符的结合性。 下面是一个…

JAVA基础03-scanner,输出,循环,if的使用以及eclipse的安装

目录 scanner的使用 if语句的使用 eclipse的使用 switch语句的使用 输出方法的使用 循环语句 scanner的使用 实现用户数据的交互&#xff0c;用户通过终端输入数据 注意&#xff1a;使用Scanner需要导包 在程序开头加上&#xff1a;import java.util.Scanner; //由于S…

2024免费Mac苹果解压压缩包软件BetterZip5

在2024年&#xff0c;对于Mac电脑用户来说&#xff0c;如果你想要无需解压就能快速查看压缩文档的内容&#xff0c;BetterZip是一个极佳的选择。这款软件不仅支持多种格式的压缩和解压&#xff0c;如zip、rar、7z、tar等&#xff0c;还具备丰富的功能和设置&#xff0c;包括预览…

异地组网怎么管理?

在当今信息化时代&#xff0c;随着企业的业务扩张和员工的分布&#xff0c;异地组网已经成为越来越多企业的需求。异地组网管理相对来说是一项复杂而繁琐的任务。本文将介绍一种名为【天联】的管理解决方案&#xff0c;帮助企业更好地管理异地组网。 【天联】组网的优势 【天联…

《pytorch深度学习实战》学习笔记第2章

第2章 预训练网络 讨论3种常用的预训练模型&#xff1a; 1、根据内容对图像进行标记&#xff08;识别&#xff09; 2、从真实图像中生成新图像&#xff08;GAN&#xff09; 3、使用正确的英语句子来描述图像内容&#xff08;自然语言&#xff09; 2.1 获取一个预训练好的网络…

c++宏有什么离谱操作?

Boost.Preprocessor确实是一个非常强大而复杂的C宏库&#xff0c;专门用于元编程&#xff0c;即在编译时进行代码生成和变换。我这里有一套编程入门教程&#xff0c;不仅包含了详细的视频讲解&#xff0c;项目实战。如果你渴望学习编程不妨点个关注&#xff0c;给个评论222&…

WordPress建站教程:10步快速搭建个人网站

WordPress是一个广泛使用的内容管理系统&#xff08;CMS&#xff09;&#xff0c;凭借其用户友好的界面和大量可定制的主题和插件&#xff0c;为WordPress 提供了多功能性和灵活性&#xff0c;可用于创建各种类型的网站&#xff0c;包括个人博客、B2B企业网站、B2C外贸网站等&a…

骨架屏:提升用户体验的巧妙技巧

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

CleanMyMac2024拥有优化Mac电脑所需的所有工具,深层清理、恶意软件移除、用CleanMyMac X就够了!

CleanMyMac X 拥有优化 Mac 电脑所需的所有工具&#xff1a;深层清理、恶意软件移除、性能提升…… 优化 Mac 电脑&#xff0c;用 CleanMyMac X 就够了&#xff01; CleanMyMac作为一款专为Mac用户设计的系统清理和优化软件&#xff0c;通过其独特的功能和特性&#xff0c;帮助…

Linux集群(二)集群搭建与keeplived配置

目录 一、集群搭建 1.复制3份Tomcat 2.测试Tomcat 3. 配置nginx.conf配置文件 二、keeplived 1.什么是keeplived 2.keeplived特点 3.下载和安装 3.1下载 3.2安装 3.3配置keeplived.conf配置文件 3.4测试 一、集群搭建 集群的主要目的是解决并发的问题。 1.复制3…