zl程序教程

您现在的位置是:首页 >  后端

当前栏目

项目实战:ASP.NET:B/S结构 个人空间相册、照片上传下载系统

NetASP项目系统 实战 结构 照片 相册
2023-06-13 09:12:31 时间

大家好,又见面了,我是你们的朋友全栈君。

项目实战: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