ASP。net 测验
Login.aspx using 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("<script>alert('密码错误');location.href='Login.aspx'</script>");
}
}
图片上传 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("<script>alert('您上传的格式不正确')</script>");
}
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("<script>alert('文件上传成功')</script>");
}
else
{
Response.Write("<script>alert('文件上传失败')</script>");
} } }
}
在线统计 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#" %> <script runat="server"> void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
Application["count"] = 0; } void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
Application.Lock();
Application["count"] = (int)Application["count"] + 1;
Application.UnLock(); } void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。
Application.Lock();
Application["count"] = (int)Application["count"] -1;
Application.UnLock(); } </script>
<?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="con" value="Server=localhost;Database=cjp;Uid=root;Pwd=;charset=utf8;allow zero datetime=true"/> </appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="403.htm" />
<error statusCode="404" redirect="404.htm" />
</customErrors>
<sessionState timeout="300" mode="InProc" /> </system.web> </configuration>
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 中显示一下当前在线人数
ASP。net 测验的更多相关文章
- 自己动手实现html去标签和文本提取
随意观看 [TOC] 工具 python3.6 正则表达式(别的语言思路一样,容易借鉴) python正则表达式:flags的应用 这里主要介绍一下re.compile(pattern[, flags ...
- asp.net core 2.2 中的过滤器/筛选器(上)
ASP.NET Core中的过滤器/筛选器 通过使用 ASP.NET Core MVC 中的筛选器,可在请求处理管道中的特定阶段之前或之后运行代码. 注意:本主题不适用于 Razor 页面. ASP. ...
- Web API 2 入门——使用ASP.NET Web API和Angular.js构建单页应用程序(SPA)(谷歌翻译)
在这篇文章中 概观 演习 概要 由网络营 下载网络营训练包 在传统的Web应用程序中,客户机(浏览器)通过请求页面启动与服务器的通信.然后,服务器处理请求,并将页面的HTML发送给客户端.在与页面的后 ...
- SQL-W3School-测验:SQL 测验
ylbtech-SQL-W3School-测验:SQL 测验 1.返回顶部 1. 您可以通过 W3SCHOOL 的测验程序来测试您的 SQL 技能. 关于本测验 本测验包含 20 道题,每道题的最长答 ...
- SQL 测验题目(30道)
1.SQL 指的是? 您的回答:Structured Query Language 2.哪个 SQL 语句用于从数据库中提取数据? 您的回答:SELECT 3.哪条 SQL 语句用于更新数据库中的数据 ...
- ASP.NET Core 之 Identity 入门(一)
前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...
- Asp.Net Mvc 使用WebUploader 多图片上传
来博客园有一个月了,哈哈.在这里学到了很多东西.今天也来试着分享一下学到的东西.希望能和大家做朋友共同进步. 最近由于项目需要上传多张图片,对于我这只菜鸟来说,以前上传图片都是直接拖得控件啊,而且还是 ...
- ASP.NET Core 中的那些认证中间件及一些重要知识点
前言 在读这篇文章之间,建议先看一下我的 ASP.NET Core 之 Identity 入门系列(一,二,三)奠定一下基础. 有关于 Authentication 的知识太广,所以本篇介绍几个在 A ...
- ASP.NET Core应用的错误处理[3]:ExceptionHandlerMiddleware中间件如何呈现“定制化错误页面”
DeveloperExceptionPageMiddleware中间件利用呈现出来的错误页面实现抛出异常和当前请求的详细信息以辅助开发人员更好地进行纠错诊断工作,而ExceptionHandlerMi ...
随机推荐
- rman恢复误删除的一张表(不完全恢复)
恢复误删除的一张表可以使用很多方法,如日志挖掘.闪回等,rman恢复(不完全恢复)肯定不是最好的,也不建议用, 现在我们只是演示一下这种恢复. 1 RMAN备份数据库 2创建测试表 3查看此时的SCN ...
- 模拟状态为active的日志损坏的数据恢复实验(不完全恢复)
1查看当前日志状态 首先不完全恢复是会丢失数据的,由此在当前打开的数据中我们创建一些测试数据,用来验证当我们进行完不完全恢复后该数据是否还存在. 2模拟删除CURRENT状态的日志 3启动数据验证错误 ...
- bzoj1150: [CTSC2007]数据备份Backup--贪心+优先队列维护堆
题目大意:将k对点两两相连,求最小长度 易证得,最优方案中,相连的办公楼一定是取相邻的比取不相邻的要更优 然后就可以用贪心来做这道题了.. 之前向CZL大神学习了用堆来贪心的做法orz 大概思路就是将 ...
- SpringBoot项目部署与服务配置
spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项 ...
- Redis菜鸟汇总
1.是完全开源免费的,用C语言编写的,遵守BSD协议,是一个高性能的(key/value)分布式内存数据库,基于内存运行并支持持久化的NoSQL数据库,是当前最热门的NoSql数据库之一,也被人们称为 ...
- python操作Excel读写--使用xlrd和xlwt
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 进入到解压文件路径,输入 setup.py ...
- Jquery的命名冲突
$是Jquery的别名,为了编码方便,我们可以使用$符号来调用Jquery的函数.然而,当我们引入多个JS库的时候,如果另外一个库中也引用了$符号作为别名的话,那么我们在使用$符号的时候,由于同一个作 ...
- Oracle 11g的Redo Log和Archive Log的分析方法
自Oracle 11g起,无需设置UTL_FILE_DIR就可以使用LOGMNR对本地数据库的日志进行分析,以下是使用LOGMNR的DICT_FROM_ONLINE_CATALOG分析REDO和归档日 ...
- Masonry学习分享
不完整目录 •UIScrollView 应用Masonry的正确用法 •tableHeaderView使用Masonry •同向文字显示优先级 1.基础篇 1.1基础使用 1.1.1运行效果 1.1. ...
- http cache 原理实战演习
有篇博文介绍的原理已经比较清楚了,见下面链接, 本文给出实验结果. http://www.cnblogs.com/cocowool/archive/2011/08/22/2149929.html La ...