div弹出层的ajax登录(Jquery版+c#)(2)


<%@ WebHandler Language="C#" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Web.SessionState;

public class Handler : IHttpHandler,IRequiresSessionState {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string tempValue = string.Empty;
if (context.Request["flag"] == null)
context.Response.Write("error");
else
{
string flag = context.Request["flag"];
switch (flag)
{
case "server":
tempValue = this.GetServers();
break;
case "islogin":
tempValue = (context.Session["login"] != null).ToString();//判断是否登录到SQL
break;
case "login":
tempValue = IsLogin(context);
break;
default:
tempValue = "error";
break;
}
}
context.Response.Write(tempValue);
}

/// <summary>
/// 加载SQL Server 服务列表
/// </summary>
/// <returns></returns>
private string GetServers()
{
IList<string> list = Common.GetServers();
if (list == null || list.Count == 0) return "empty";
StringBuilder sb = new StringBuilder();
foreach (string s in list)
{
sb.AppendFormat("<div class=https://www.jb51.net/article/\"second\"><a href=https://www.jb51.net/article/\"javascript:void(0);\" title=https://www.jb51.net/article/\"{0}\">{0}</a></div>", s);
}
return sb.ToString();
}

/// <summary>
/// 登录SQL Server
/// </summary>
/// <param></param>
/// <returns></returns>
private string IsLogin(HttpContext context)
{
if (context.Request["user"] == null || context.Request["password"] == null)
{
context.Session["login"] = "success";
return "";
}
else
{
string server = HttpUtility.UrlDecode(context.Request["sqlServer"]);
string user = HttpUtility.UrlDecode(context.Request["user"]);
string password = HttpUtility.UrlDecode(context.Request["password"]);
string sqlConstring;
if (Common.IsLogin(server, user, password, out sqlConstring))
{
context.Session["login"] = sqlConstring;
return "True";
}
else
{
return "False";
}
}
}

public bool IsReusable {
get {
return false;
}
}
}



Common.cs

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjdszg.html