13,347
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="signin.aspx.cs" Inherits="signin" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta charset="utf-8" />
<title>爱心拾物网登录界面</title>
<!--用百度的静态资源库的cdn安装bootstrap环境-->
<!-- Bootstrap 核心 CSS 文件 -->
<link href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<!--font-awesome 核心我CSS 文件-->
<link href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<!-- 在bootstrap.min.js 之前引入 -->
<script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script>
<!-- Bootstrap 核心 JavaScript 文件 -->
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<!--jquery.validate-->
<script type="text/javascript" src="scripts/jquery.validate.min.js" ></script>
<script type="text/javascript" src="scripts/message.js" ></script>
<style type="text/css">
body{background: url(img/4.jpg) no-repeat;background-size: cover;font-size: 16px;}
.form{background: rgba(255,255,255,0.2);width:400px;margin:100px auto;}
#login_form{display: block;}
#register_form{display: none;}
.fa{display: inline-block;top: 27px;left: 6px;position: relative;color: #ccc;}
input[type="text"],input[type="password"]{padding-left:26px;}
.checkbox{padding-left:21px;}
</style>
</head>
<body>
<!--
基础知识:
网格系统:通过行和列布局
行必须放在container内
手机用col-xs-*
平板用col-sm-*
笔记本或普通台式电脑用col-md-*
大型设备台式电脑用col-lg-*
为了兼容多个设备,可以用多个col-*-*来控制;
-->
<!--
从案例学知识,来做一个登录,注册页面
用到font-awesome 4.3.0;bootstrap 3.3.0;jQuery Validate
-->
<div class="container">
<div class="form row">
<form class="form-horizontal col-sm-offset-3 col-md-offset-3" id="login" name="login" action="?Action=Login" method="post">
<h3 class="form-title">请登录爱心拾物网</h3>
<div class="col-sm-9 col-md-9">
<div class="form-group">
<i class="fa fa-user fa-lg"></i>
<input class="form-control required" type="text" placeholder="Username" name="UserName" id="UserName" autofocus="autofocus" maxlength="20"/>
</div>
<div class="form-group">
<i class="fa fa-lock fa-lg"></i>
<input class="form-control required" type="password" placeholder="Password" name="UserPassword" id="UserPassword" maxlength="8"/>
</div>
<div class="form-group">
<label class="checkbox">
<input type="checkbox" name="remember" value="1"/> Remember me
</label>
<hr />
<a href="javascript:;" id="register_btn" class="">Create an account</a>
</div>
<div class="form-group">
<input type="sub" class="btn btn-success pull-right" value="Login " onclick="document.login.submit()"/>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="scripts/main.js" ></script>
</body>
</html>
public partial class signin : System.Web.UI.Page
{
protected string Action = "";
protected class UserLoginInfo
{
public string UserName = "";
public string UserPassword = "";
}
protected UserLoginInfo _UserLoginInfo = new UserLoginInfo();
protected void Page_Load(object sender, EventArgs e)
{
Init_WebControls();
}
protected void Init_WebControls()
{
try
{
if (!string.IsNullOrEmpty(Request.QueryString["Action"]))
{
Action = Request.QueryString["Action"].Trim().ToLower();
}
switch (Action)
{
case "Login":
if (!string.IsNullOrEmpty(Request.Form["UserName"]) && !string.IsNullOrEmpty(Request.Form["UserPassWord"]))
{
_UserLoginInfo.UserName = Request.Form["UserName"].ToString();
_UserLoginInfo.UserPassword = Request.Form["UserPassWord"].ToString();
string user = "select Username,Password from users where Username='" + _UserLoginInfo.UserName + "' and Password='" + _UserLoginInfo.UserPassword + "'";
string connectionString = ConfigurationManager.ConnectionStrings["LovingHome"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(user,conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 1)
{
Response.Redirect("Index.aspx", false);//防止Response.End 方法终止页的执行
}
else
{
Response.Write("<Script Language=JavaScript>alert('密码或用户名错误,请重试!');</Script>");
}
}
break;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}