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框架中的基础类库,用于实现一些基本的类。

login.aspx.cs的更多相关文章

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs&qu ...

  2. aspx文件、aspx.cs文件、aspx.designer.cs文件之讲解

    .aspx文件:(页面)书写页面代码.存储的是页面design代码.只是放各个控件的代码,处理代码一般放在.cs文件中. .aspx.cs文件:(代码隐藏页)书写类代码.存储的是程序代码.一般存放与数 ...

  3. 新建应用母版页的网页index.aspx,about.aspx,login.aspx

    转:http://www.netfoucs.com/liu_111111/article/details/8433491 -----------index.aspx:----------------- ...

  4. 在VS中建立.aspx,.cs,.designer.cs之间的级联关系

    <Compile Include="..\Admin\Actions.aspx.cs"> <DependentUpon>Actions.aspx</D ...

  5. aspx页面前端使用js 调用aspx.cs后台的方法,不回传

    本次使用 Ajax.dll,AjaxPro.dll 两个类库 1.首先添加引用:Ajax.dll,AjaxPro.dll 文件在 Libiary 目录下 2.配置 WebConfig 属性 将 下面2 ...

  6. 【转】aspx与aspx.cs的关系

    原文地址: http://www.cnblogs.com/axzxs2001/archive/2009/01/19/1378383.html 在vs中,有很多朋友问起,在一个网站项目中的aspx和as ...

  7. WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据

    WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...

  8. jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子

    一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...

  9. 用正则表达式在注册页面(js/aspx.cs)的验证

    1.验证邮箱(用户名) JS页面中: 首先定义变量和正则 var usermail = $("#usermail" ).val(); var username= /^([a-zA- ...

随机推荐

  1. 一种微信直播H5直播与存储回放的HLS摄像机方案

    接上篇 在上一篇博客<一种流量成本节省60%以上的手机直播微信直播H5直播幼儿园直播方案>中,我们一共介绍了两种省钱的HLS直播途径: 方案一:编码器或者内网推流直接对接云存储的场景 如果 ...

  2. hdu 4667 Building Fence < 计算几何模板>

    //大白p263 #include <cmath> #include <cstdio> #include <cstring> #include <string ...

  3. 引用变量的类型强转以及InstanceOf方法的使用

    引用到的类: class Person{ String name; } class Student extends Person{ String sut_no; } class ClassMate e ...

  4. 服务器安装tensorflow导入模块报错Illegal instruction (core dumped)

    在ubuntu上安装tensorflow后导入模块显示Illegal instruction (core dumped) 服务器的版本是Ubuntu 16.04.5 降低版本,成功导入模块 pip3 ...

  5. GIT笔记:将项目发布到码云

    GIT笔记:将项目发布到码云 发布步骤 1.码云创建项目 记录下项目的远程地址: https://gitee.com/mrsaber/ms_supplyAndSale.git 2.在本地创建GIT仓库 ...

  6. 多线程(三) iOS中的锁

    锁的类别:互斥锁,递归锁,条件锁,自旋锁等 锁的实现方式:NSLock,NSRecursiveLock, NSConditionLock,@synchronized,GCD的信号量等 下面说一下常用的 ...

  7. POJ 2348 Euclid Game (模拟题)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7942   Accepted: 3227 Des ...

  8. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  9. 分布式任务调度平台XXL-Job搭建

    下载: https://github.com/xuxueli/xxl-job 下载 然后倒入到自己的工程里面 引入后: 导入数据:跑一边 导入: 修改: Window -->show view- ...

  10. jquery 用addClass之后 class有对应的事件,为什么要重新绑定一下事件呢

    假设有元素A,B,C,其中A和B都有class属性cls,如果在页面加载完成时,给具有class属性为cls的元素绑定某一事件,例如click,执行事件时调用alert.也就是说,页面加载完成后A和B ...