62,046
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
$(function () {
//绑定登录按钮
$("#loginbtn").click(function () {
var user_name = $("#user_name").val();
var user_password = $("#user_password").val();
$.post("ajax/AjaxLoginVai.ashx", { user_name: user_name, user_password: user_password }, function (data) {
if (data == "ok") {
window.location.href = "Index.aspx";
} else if (data == "admin_ok") {
window.location.href = "Admin_UserList.aspx";
} else {
alert(data);
}
})
});
});
</script>
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" valign="bottom">用户名:</td>
</tr>
<tr>
<td><input type="text" class="login_input login_user" value="" id="user_name" /></td>
</tr>
<tr>
<td height="35" valign="bottom">密 码:</td>
</tr>
<tr>
<td><input type="password" class="login_input login_password" value="" id="user_password" /></td>
</tr>
<tr>
<td height="60" valign="bottom"><a href="javascript:void(0);" class="btn btn-block btn-login" id="loginbtn">登录</a></td>
</tr>
</table>
一般处理程序后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Tway.BLL;
using System.Web.SessionState;
namespace Takeaway.Merchant.ajax
{
/// <summary>
/// AjaxLoginVai 的摘要说明
/// </summary>
public class AjaxLoginVai : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
var user_name = context.Request["user_name"].Trim();
var user_password = context.Request["user_password"].Trim();
UserInfoService userinfoservice = new UserInfoService();
while (true)
{
//验证用户
bool res = userinfoservice.ValiUser(user_name, user_password);
if (!res)
{
context.Response.Clear();
context.Response.Write("用户名或密码错误");
context.Response.End();
break;
}
//验证用户类型
var user_id = userinfoservice.GetUserId(user_name);
int usertype = userinfoservice.GetUserInfoById(user_id).Type;
if (usertype != 2 && usertype != 200)//不是商家也不是管理员
{
context.Response.Clear();
context.Response.Write("很抱歉,您还不是商家,或申请尚未通过审核");
context.Response.End();
break;
}
if (usertype == 200)//是管理员
{
//管理员,存入Session
context.Session["Admin_User_Id"] = user_id;
context.Session["Admin_User_Name"] = user_name;
context.Response.Clear();
context.Response.Write("admin_ok");
context.Response.End();
break;
}
//正常商家,存入Session
context.Session["User_Id"] = user_id;
context.Session["User_Name"] = user_name;
context.Response.Clear();
context.Response.Write("ok");
context.Response.End();
break;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
<input id="login" name=login type="submit" runat="server" onserverclick="login_click" value="登录">
后台写事件:
protected void login_click(object sender,EventArgs e)
{
...balabalabala...
}