博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP。net 测验
阅读量:4457 次
发布时间:2019-06-08

本文共 4711 字,大约阅读时间需要 15 分钟。

Login.aspxusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using DBHelper;using MySql.Data.MySqlClient;public partial class Login : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            HttpCookie hc = null;            if (Request.Cookies["LoginCookie"] != null)            {                hc = Request.Cookies["LoginCookie"];                this.TextBox1.Text = hc["username"];                this.TextBox2.Text = hc["password"];                               Session.RemoveAll();            }                              }    }    protected void Button2_Click(object sender, EventArgs e)    {        string username = this.TextBox1.Text;        string password = this.TextBox2.Text;        string sql = "select id,name,password from login where name=@username and password=@password";        MySqlParameter p1 = new MySqlParameter("@username", username);        MySqlParameter p2 = new MySqlParameter("@password", password);        MySqlParameter[] pa = new MySqlParameter[] { p1, p2 };        MySqlDataReader dr = SqlHelper.ExecuteReaderText(sql, pa);        while (dr.Read())         {            //cookie            HttpCookie hc = new HttpCookie("LoginCookie");            hc["id"] = dr[0].ToString();            hc["username"] = dr[1].ToString();            hc["password"] = dr[2].ToString();            hc.Expires = DateTime.Now.AddDays(1);            Response.Cookies.Add(hc);            //session            LoginSession Lseiion = new LoginSession();            Lseiion.id = dr[0].ToString();            Lseiion.name = dr[1].ToString();            Session["LoginSession"] = Lseiion;                        Response.Redirect("Default.aspx");                                }        Response.Write("");    }}

  

图片上传using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using MySql.Data.MySqlClient;using DBHelper;public partial class ImageUpload : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {                        if (Session["LoginSession"] == null)            {                Response.Redirect("Login.aspx");            }                    }    }    protected void Button1_Click(object sender, EventArgs e)    {        string FileName = FileUpload1.PostedFile.FileName;        string File_Abbr = Server.MapPath("images/");//路径        string extion = Path.GetExtension(FileName);//格式        if (extion != ".jpg")        {            Response.Write("");        }        else         {            if (!Directory.Exists(File_Abbr))            {                Directory.CreateDirectory(File_Abbr);            }            string NameTime = DateTime.Now.Ticks.ToString() + extion;            FileUpload1.SaveAs(File_Abbr + NameTime);            string sql = "insert into img(imgpath)values(@paths)";            MySqlParameter[] pa = new MySqlParameter[] { new MySqlParameter("@paths", File_Abbr + NameTime) };            int i = SqlHelper.ExecteNonQueryText(sql, pa);            if (i > 0)            {                this.Image1.ImageUrl = @"./images/" + NameTime;                Session["IsSubmit"] = true;                Response.Write("");            }            else             {                Response.Write("");            }                   }    }}

  

在线统计using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Online : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {                       if (Session["LoginSession"] == null)            {                Response.Redirect("Login.aspx");            }                             }    }    protected void Button1_Click(object sender, EventArgs e)    {               Response.Write("当前在线人数为:" + Application["count"]);    }}

  

应用配置<%@ Application Language="C#" %>

  

  

 

1、登录页面Login.aspx

① 页面加载 ,如果存在用户cookie,那么将cookie中的内容还原到用户名和密码上,
将存在的session全部删除

② 点击登录按钮,数据库验证用户名 和 密码 ,通过后保存cookie,session,然后跳转到主页面Index.aspx

2、主页面使用Menu控件作为菜单导航

3、使用页面导航菜单Menu导航到图片上传页面ImageUpload.aspx,session如果不存在或已经过期则跳转到登录页面,将图片上传文件上传到的网站路径image文件夹下,上传成功后,图片在页面上用image控件显示出来。

图片信息需要保存到数据库

4、使用页面导航菜单Menu导航到 在线人数统计页面Online.aspx ,session如果不存在或已经过期则跳转到登录页面,在Online.aspx 中显示一下当前在线人数

 

转载于:https://www.cnblogs.com/mengluo/p/6026687.html

你可能感兴趣的文章
1.基础数据类型的初识 字符串 bool 整型 if else elif
查看>>
【设计模式】4、原型模式
查看>>
进入meta模式关闭背光灯
查看>>
webstorm上svn的安装使用
查看>>
【JEECG技术文档】数据权限自定义SQL表达式用法说明
查看>>
使用 Bootstrap Typeahead 组件
查看>>
linux_cacti 配置之 安装snmp 服务
查看>>
201407-至今
查看>>
c# 应用事务
查看>>
优化杭州某著名电子商务网站高并发千万级大型数据库经验之- SQL语句优化(转)...
查看>>
WPF——TargetNullValue(如何在绑定空值显示默认字符)
查看>>
Linux之crontab
查看>>
清除浮动
查看>>
CenOS+宝塔(模拟)上线博客项目
查看>>
loadrunner Vugen-Tools General-Options-Replay设置
查看>>
redis限频
查看>>
Floyd判圈算法
查看>>
接口,lambda表达式与内部类(二)
查看>>
Phabricator是什么,代码审查工具
查看>>
Java虚拟机类加载机制
查看>>