项目实战:ASP.NET:B/S结构 个人空间相册、照片上传下载系统
大家好,又见面了,我是你们的朋友全栈君。
项目实战:ASP.NET:B/S结构 个人空间相册、照片上传下载系
统
编辑环境:win10_x64 /VS2015/ SqlServer2012
项目:asp.net
项目简介:只是具有基本的登录功能,上传相关信息,图片, 提供下载,相册功能,熟悉表格和基本的前后台程序
其他:这是写的第一个asp.net,只是为了熟悉和了解asp.net项目和相关的知识。本次只是简单地前台html页面和后台的以一般应用处理程序的结合熟悉与使用,还暂时没有使用到相关的MVC和专业的编程规程,只是为了熟悉和使用,后面还有比较大的程序, 第三个asp.net项目,则是完全的商业化编程,规范,具有很大难度[相对于我],有着很好的编程思路和项目实战经验。【下面提供项目源码和数据库的链接】
==================================================================
项目运行效果
==================================================================
==================================================================
项目思路分析:
==================================================================
==================================================================
项目主要源码部分:
==================================================================
简单地前台HTML页面加上,对应的后台处理程序, 组合成一个简单微型网站,功能具有基本的登录功能,上传相关信息,图片, 提供下载,相册功能,熟悉表格和基本的前后台程序。
个人觉里面比较重要的的就是图片的上传和查看个人空间相册功能,和就是下载功能
==================================================================
项目源码:
==================================================================
//连接数据库代码
<connectionStrings >
<add name="connStr" connectionString="server=192.168.186.128;uid=sa;pwd=Aq123456;database=huahua"/>
<!--<add key="ConnectionString" value="server=192.168.186.128;database=bbs;uid=sa;pwd=Aq123456"/>-->
</connectionStrings>
//登录页面
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>登录入口界面</title>
<meta charset="utf-8" />
</head>
<body>
<h1>登录入口界面</h1>
<span></span>
<form method="post" action="Index.ashx"> <!--需要跳转到处理程序里面-->
<table border="1" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="text" name="userpass" /></td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" value="登录" /> </td>
</tr>
</table>
</form>
</body>
</html>
//登录验证后台,应用处理程序
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
namespace hua.test
{
/// <summary>
/// Index 的摘要说明
/// </summary>
public class Index : IHttpHandler
{
private readonly static string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
public void ProcessRequest(HttpContext context)
{
//Response:服务器对客户端的响应
context.Response.ContentType = "text/html";
//context.Response.Write("Hello World");
string id = context.Request.Form["username"];
string pass = context.Request.Form["userpass"];
//*****************************************************************************************************
//方式一:手动验证的账号密码
//if (name.Equals("admin") && pass.Equals("123"))
//{
// //重定向进行跳转
// context.Response.Redirect("HtmlPage1.html");
//}
//else
//{
// string filePath = context.Request.MapPath("Index.html"); //得到指定文件的绝对路径
// string fileContext = File.ReadAllText(filePath); //得到index.html里面的文本内容
// fileContext = fileContext.Replace("$msg", "<h1>您输入的账号或者密码错误,请重新输入!</h1>"); //把文本里指的内容进行替换
// context.Response.Write(fileContext); //将替换后的内容输出到客户端(浏览器)
//}
//*****************************************************************************************************
// SELECT [s_id]
//,[s_passed]
//,[s_name]
//,[s_time]
//,[s_email]
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "select * from dbo.Table_1 where @s_id = s_id and @s_passed = s_passed";
using (SqlDataAdapter adapter = new SqlDataAdapter(sql, connStr))
{
SqlParameter[] pars = { new SqlParameter("@s_id", SqlDbType.NVarChar),
new SqlParameter("@s_passed", SqlDbType.NVarChar)};
pars[0].Value = id;
pars[1].Value = pass;
adapter.SelectCommand.Parameters.AddRange(pars);
DataTable dt = new DataTable();
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];//取第一行数据 fileupload
string filePath = context.Request.MapPath("fileupload/fileupload.html");
string fileContext = File.ReadAllText(filePath);
fileContext = fileContext.Replace("$id", id);
context.Response.Write(fileContext);
// context.Response.Redirect("fileupload/FileUpload.html?id=203");//重定向跳转
}
else
{
string filePath = context.Request.MapPath("index.html");
string fileContext = File.ReadAllText(filePath);
fileContext = fileContext.Replace("<span></span>", "输入的用户名或者密码错误 ,请重新输入");
context.Response.Write(fileContext);
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
由于代码比较多, 这里就这一个做一个示范。下面附上
================================================ 源码下载:
B/S结构 个人空间相册、照片上传下载系统
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/157468.html原文链接:https://javaforall.cn
相关文章
- ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
- .netLinux下部署ASP.NET环境指南(linux部署asp)
- asp.net的web服务MSSQL检测ASP.NET的Web服务——利用它构建更棒的站点(mssql检测基于)
- C与MySQL融合打造优秀的网站开发体验(c net mysql)
- ASP.NET上传图片并生成可带版权信息的缩略图
- asp.net下url传递中文的解决方案
- 比较不错的asp模板引终极讲解(WEB开发之ASP模式)
- ASP.NET输出PNG图片时出现GDI+一般性错误的解决方法
- asp.net结合YUI3.0小示例
- Asp.Net动态页面转静态页面主要代码
- 记录游客页面访问IP的简易实现代码(asp.net+txt)
- ASP.NET前后台调用方法
- asp页面和Asp.net页面传中文参数UrlEncode编码以及接收解码
- asp.net下用Aspose.Wordsfor.NET动态生成word文档中的数据表格的方法
- asp.net(c#)下读取word文档的方法小结
- asp.net数据绑定时对数据列做个性化处理
- 在asp.net(c#)下实现调用cmd的方法
- asp.net运行提示未将对象引用设置到对象的实例错误解决方法
- asp.net程序优化尽量减少数据库连接操作
- 答你所问.NET小常识方便学习asp.net的朋友
- 浅析ASP.NET安全性分析(加强asp.net1.1/2.0安全性)
- asp.net学习之路项目整体框架简单的搭建
- asp.net(c#)动态修改webservice的地址和端口(动态修改配置文件)
- asp.net请求输入到输出的全过程及httpHandler和httpModuler详细介绍
- .Net中导出数据到Excel(asp.net和winform程序中)
- asp.net中System.Timers.Timer的使用方法
- c#asp.net动态创建sql数据库表的方法
- ASP.NET连接SQL数据库的简单实例代码
- ASP.NET实现页面传值的几种方法小结