代码如下:
// JScript 文件
function usersLogon()
{
var userName = document.getElementById("txtuserName").value;
var password = document.getElementById("txtpassword").value;
var checkCode = document.getElementById("txtCheckCode").value;
var response = userControl_logon.CheckCodeIsRight(checkCode).value;
if(userName == "")
{
document.getElementById("txtuserName").focus();
return false;
}
else if(password == "")
{
document.getElementById("txtpassword").focus();
return false;
}
else if(checkCode =="")
{
document.getElementById("txtCheckCode").focus();
return false;
}
else
{
if(response == true)
{
//判断用户是否存在
userControl_logon.userNameAndPasswordIsExist(userName,password,userNameIsRight);
}
else
{
alert("验证码出错");
userControl_logon.checkCodeOperaotr(refreshCheckCode);
document.getElementById("txtpassword").value = "";
}
}
}
function userNameIsRight(res)
{
var userName = document.getElementById("txtuserName").value;
if(res.value == true)
{
//用户存在,但要看此用户有没有进入管理留言版权限,
userControl_logon.userNameIsRight(userName,CallBack);
}
else
{
alert("用户名或密码错误");
document.getElementById("txtpassword").value = "";
OnLoad_checkCode();
}
}
function CallBack(res)
{
if(res.value == true)
{
hideLogon();
var url = userControl_logon.returnUrl();
if ( url.value == 404)
{
showDefault();
}
else
{
document.getElementById("Url").innerHTML = '<a href="' + url.value + '">' + url.value + '</a>'
}
}
else
{
alert("对不起你的权限不够");
document.getElementById("txtpassword").value = "";
OnLoad_checkCode();
}
}
//隐藏登录框
function hideLogon()
{
var element = document.getElementById("hideLogon")
element.style.display = "none"
}
//显示返回首页
function showDefault()
{
var element = document.getElementById("Returndefault")
element.style.display = "block"
}
function OnLoad_checkCode()
{
userControl_logon.checkCodeOperaotr(refreshCheckCode);
document.getElementById("txtuserName").focus();
// return false;
}
///重新得到新的验证吗
function refreshCheckCode(res)
{
document.getElementById("txtCheckCode").value = "";
document.getElementById("lblNumber").innerHTML = res.value;
}
function abce()
{
alert(document.getElementById("lblNumber").value)
}
下面代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using LHB_SQL_2005;
public partial class userControl_logon : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(userControl_logon));
}
}
[AjaxPro.AjaxMethod]
public static string checkCodeOperaotr()
{
string _checkCode = GeneralMethod.GenerateCheckCode();
System.Web.HttpContext.Current.Session["checkCode"] = _checkCode;
//返回验证码
return _checkCode;
}
/// <summary>
/// 判断验证是否正确
/// </summary>
/// <param name="checkCode"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool CheckCodeIsRight(string checkCode)
{
string _checkCode = (string)(System.Web.HttpContext.Current.Session["checkCode"]);
if (_checkCode == checkCode)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断用户名及密码添加是否正确
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="_password">用户名密码</param>
/// <returns>bool</returns>
[AjaxPro.AjaxMethod]
public static bool userNameAndPasswordIsExist(string userName, string _password)
{
string password = GeneralMethod.ToEncryptPassword(_password);
string executeString = "SELECT COUNT(*) FROM users WHERE userName = '" + userName.ToString() + "' AND password = '" + password + "'";
int count = int.Parse(GetCommand.ExecuteScalar(executeString));
if (count == 1)
{
System.Web.HttpContext.Current.Session["userName"] = userName;
return true;
}
else
{
return false;
}
}
/// <summary>
/// 判断用户是不是有这进入管理留言版的权限
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool userNameIsRight(string userName)
{
string executeString = "SELECT [right] FROM role WHERE usersId = (select userNameId from users where userName = '" + userName + "')";
int count = int.Parse(GetCommand.ExecuteScalar(executeString));
if (count > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 返回Url值
/// </summary>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static string returnUrl()
{
string url = "";
try
{
url = System.Web.HttpContext.Current.Session["url"].ToString();
}
catch
{
url ="404";
}
return url;
}
}
下面是页面代码
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="logon.ascx.cs" Inherits="userControl_logon" %>
<script language="javascript" type="text/javascript" src="../JavaScript/logon.js">
</script>
<script language="javascript" type="text/javascript" src="JavaScript/logon.js">
</script>
<link href="../CSS/table_css.css" rel="stylesheet" type="text/css" />
<link href="CSS/table_css.css" rel="stylesheet" type="text/css" />
<body onload="OnLoad_checkCode();">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table id="hideLogon" border="0" cellpadding="0" cellspacing="0" style="display:block;">
<tr>
<td style="background-color: #99ccff">用户名:</td>
<td><input type="text" id="txtuserName" style="width: 105px" /></td>
</tr>
<tr>
<td style="background-color: #99ccff">密 码:</td>
<td>
<input id="txtpassword" type="password" style="width: 105px" /></td>
</tr>
<tr>
<td style="background-color: #99ccff">验证码:</td>
<td style="background-color: #99ccff">
<input type= "text" id="txtCheckCode" style=" width:60px" /><label id="lblNumber"></label></td>
</tr>
<tr>
<td style="background-color: #99ccff"></td>
<td style="background-color: #99ccff">
<input type="button" onclick="usersLogon();" value="登录" id="btnLogon" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td >
<div id="Url"></div>
</td>
</tr>
<tr>
<td align="center">
<table id="Returndefault" border="0" cellpadding="0" cellspacing="0" style="display:none;">
<tr>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">返回首页</asp:HyperLink></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
以上所述是小编给大家介绍的基于Ajax技术实现无刷新用户登录功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
# ajax实现无刷新登录
# ajax实现用户登录
# asp.net+jquery ajax无刷新登录的实现方法
# 菜鸟蔡之Ajax复习第三篇(Ajax之无刷新登录)
# 基于jquery ajax 用户无刷新登录方法详解
# 验证码
# 首页
# 留言版
# 小编
# 是否正确
# 在此
# 给大家
# 要看
# 用户登录
# 所述
# 给我留言
# 到新
# 感谢大家
# 是否存在
# 疑问请
# 有任何
# Data
# Configuration
# System
# Security
相关文章:
Swift开发中switch语句值绑定模式
C#怎么使用委托和事件 C# delegate与event编程方法
如何获取PHP WAP自助建站系统源码?
免费制作小说封面的网站有哪些,怎么接网站批量的封面单?
清单制作人网站有哪些,近日“兴风作浪的姑奶奶”引起很多人的关注这是什么事情?
网站制作大概多少钱一个,做一个平台网站大概多少钱?
如何在橙子建站中快速调整背景颜色?
大连网站设计制作招聘信息,大连投诉网站有哪些?
建站之星备案流程有哪些注意事项?
定制建站平台哪家好?企业官网搭建与快速建站方案推荐
Android自定义控件实现温度旋转按钮效果
如何在万网自助建站平台快速创建网站?
深圳网站制作设计招聘,关于服装设计的流行趋势,哪里的资料比较全面?
c# 在高并发场景下,委托和接口调用的性能对比
制作充值网站的软件,做人力招聘为什么要自己交端口钱?
极客网站有哪些,DoNews、36氪、爱范儿、虎嗅、雷锋网、极客公园这些互联网媒体网站有什么差异?
潍坊网站制作公司有哪些,潍坊哪家招聘网站好?
海南网站制作公司有哪些,海口网是哪家的?
智能起名网站制作软件有哪些,制作logo的软件?
招商网站制作流程,网站招商广告语?
做企业网站制作流程,企业网站制作基本流程有哪些?
建站之星后台搭建步骤解析:模板选择与产品管理实操指南
C#如何在一个XML文件中查找并替换文本内容
,柠檬视频怎样兑换vip?
小自动建站系统:AI智能生成+拖拽模板,多端适配一键搭建
如何选择靠谱的建站公司加盟品牌?
建站之星如何快速生成多端适配网站?
太平洋网站制作公司,网络用语太平洋是什么意思?
建站之星Pro快速搭建教程:模板选择与功能配置指南
Swift中switch语句区间和元组模式匹配
c++如何打印函数堆栈信息_c++ backtrace函数与符号名解析【方法】
网站制作公司排行榜,四大门户网站排名?
如何快速启动建站代理加盟业务?
Swift中swift中的switch 语句
招贴海报怎么做,什么是海报招贴?
高防服务器:AI智能防御DDoS攻击与数据安全保障
详解免费开源的.NET多类型文件解压缩组件SharpZipLib(.NET组件介绍之七)
全景视频制作网站有哪些,全景图怎么做成网页?
香港服务器部署网站为何提示未备案?
非常酷的网站设计制作软件,酷培ai教育官方网站?
如何在建站宝盒中设置产品搜索功能?
如何高效搭建专业期货交易平台网站?
北京制作网站的公司排名,北京三快科技有限公司是做什么?北京三快科技?
如何快速完成中国万网建站详细流程?
如何彻底卸载建站之星软件?
番禺网站制作公司哪家值得合作,番禺图书馆新馆开放了吗?
已有域名和空间,如何快速搭建网站?
,怎么在广州志愿者网站注册?
建站主机服务器选型指南与性能优化方案解析
专业网站设计制作公司,如何制作一个企业网站,建设网站的基本步骤有哪些?
*请认真填写需求信息,我们会在24小时内与您取得联系。