login.aspx.cs

using System;                                                                 //指令+系统(命名空间)
using System.Collections.Generic;                                 // 集合,泛型 
using System.Linq;                                                         //  语言集成查询    只有.net 3.5才有 你把项目设置一下为3.5的运行环境
using System.Web;                                                        // 引用用户界面控件集前必加 system.web
using System.Web.UI;                                                     // 供的类和接口使您得以创建将作为用户界面元素出现在您的 Web 应用程序中的 ASP.NET 服务器控件和页。
using System.Web.UI.WebControls;                                 //命名空间包含一些类,可使用这些类在网页上创建 Web 服务器控件。
using wangshi.common;
using wangshi.data;

public partial class Login : System.Web.UI.Page                     这个是 声明一个  Login  类,继承自System.Web.UI.Page,它是一个公共部分类
{
protected void Page_Load(object sender, EventArgs e)           // 当然是页面加载的时候执行了函数!
{
if (!IsPostBack)                           //IsPostBack 是.net判断页面是否第一次加载的属性,这样在第一次加载的时候调用下面的函数, 在首次加载后向服务器提交数据,然后服务器把处理好的数据传递到客户端并显示出来,就叫postback.IsPostBack判断页面是否是回传,if(!Ispostback)表示一个页面只能加载一次,但可以在加载后反复postback.

{
               HttpCookie cookies = Request.Cookies["USER_COOKIE"];             // 从客户端请求中读取Cookie  
if (cookies != null) 
{
//如果Cookie不为空,则将Cookie里面的用户名和密码读取出来赋值给前台的文本框。
this.txt_username.Text = cookies["UserName"];
//this.txt_password.Attributes.Add("value", cookies["UserPassword"]);
//这里依然把记住密码的选项给选中。
this.ckb_rememer.Checked = true;
//开始登录       //创建一个 ws.V3MobileSoapClient()

ws.V3MobileSoapClient client = new ws.V3MobileSoapClient();          //ws:web service     SoapClient 就是可以基于SOAP协议访问webservice的客户端 

//定义一个类型是String的 变量 result,将某个方法的返回结果作为值赋给result;  创建的选择储蓄客户端的数据及交互的分类
string result = client.CheckAccount(cookies["UserName"], cookies["UserPassword"], Opal.CheckTag);

//使用自定义代码调试

System.Diagnostics.Debug.WriteLine(result);


StateObj _stateObj = JsonTools.GetStateObj(result);
if (_stateObj.Success)
{
BgUserInfo user = (BgUserInfo)JsonTools.ToObj(typeof(BgUserInfo), _stateObj.Memo);
if (user != null && user.Id > 0)
{
Session["opal_user"] = user;                     //储存的opal_user" 设置成user
Response.Redirect("Default.aspx");         //跳转页面的后台写法
}
}
}
}
}

protected void btn_login_Click(object sender, EventArgs e)              //当点击  btn_login_Click 时候执行的函数事件   

object类型的参数,是顶级类型             e只是一个自定义的变量罢了,它被定义为EventArgs类型

{
if (string.IsNullOrEmpty(txt_username.Text) || string.IsNullOrEmpty(txt_password.Text))     //判断用户名或密码是否为空
{

//ClientScript.RegisterStartupScript用来向前台页面注册script脚本
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert('请输入用户名或密码!');<"/script>");
return;
}
//调用web服务          
ws.V3MobileSoapClient client = new ws.V3MobileSoapClient();
string result = client.CheckAccount(txt_username.Text, txt_password.Text, Opal.CheckTag);
System.Diagnostics.Debug.WriteLine(result);
if (string.IsNullOrEmpty(result))
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert('用户名或密码错误!');<" + "/script>");
}
else
{
StateObj _stateObj = JsonTools.GetStateObj(result);
if (_stateObj.Success)
{
BgUserInfo user = (BgUserInfo)JsonTools.ToObj(typeof(BgUserInfo), _stateObj.Memo);
if (user != null)
{
Session["opal_user"] = user;
HttpCookie cookie = new HttpCookie("USER_COOKIE");
if (ckb_rememer.Checked)
{
//所有的验证信息检测之后,如果用户选择的记住密码,则将用户名和密码写入Cookie里面保存起来。
cookie.Values.Add("UserName", this.txt_username.Text.Trim());
cookie.Values.Add("UserPassword", this.txt_password.Text.Trim());
//这里是设置Cookie的过期时间,这里设置一个星期的时间,过了一个星期之后状态保持自动清空
cookie.Expires = System.DateTime.Now.AddDays(7.0);
HttpContext.Current.Response.Cookies.Add(cookie);
}
else
{
if (cookie != null)
{
//如果用户没有选择记住密码,那么立即将Cookie里面的信息情况,并且设置状态保持立即过期
Response.Cookies["USER_COOKIE"].Expires = DateTime.Now;
}
}
Response.Redirect("Default.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert('" + _stateObj.Msg + "!');<" + "/script>");
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "提醒", "<script>alert('" + _stateObj.Msg + "!');<" + "/script>");
}
}

}
}

 

 
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;

就是引用了以上四个名称空间。
引用的这几个名称空间都是.NET框架中的基础类库,用于实现一些基本的类。

转载于:https://www.cnblogs.com/sjd1118/p/7246335.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Hotel.WebForm1" EnableEventValidation="false" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" href="Assets/Libraries/Bootstrap/css/bootstrap.min.css" /> <style> body{ background-image:url(../Assets/Images/hotel4.jpg); background-size:cover; } .container-fluid{ opacity:0.9; } </style> </head> <body> <form id="form1" runat="server" > <div> <div class="container-fluid"> <div class="row" style="height:200px"></div> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4 bg-light rounded-3"> <h1 class="text-text-success text-center">皇家理工度假酒店</h1> <form> <div class="mb-3"> <label for="UserTb" class="form-label">用户名</label> <input type="text" class="form-control" id="UserTb" runat="server" required="required"> </div> <div class="mb-3"> <label for="PasswordTb" class="form-label">密码</label> <input type="password" class="form-control" id="PasswordTb" runat="server" required="required"> </div> <div class="mb-3"> <label id="ErrMsg" class="text-danger" runat="server"></label> <input type="radio" id="AdminCb" runat="server" name="Role"><label class="text-success">管理员</label> <input type="radio" id="UserCb" runat="server" name="Role"><label class="text-success">用户</label> </div> <div class="d-grid"> <asp:Button ID="LoginBtn" runat="server" Text="登陆" class="btn btn-success btn-block" OnClick="LoginBtn_Click" /> </div> <br /> </form> </div> <div class="col-md-4"></div> </div> </div> </div> </form> </body> </html>我在form中添加了align=center属性但是删除后却依旧运行了原先配置
最新发布
05-27

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值