日期:2014-05-17 浏览次数:20468 次
protected void Button2_Click(object sender, EventArgs e) { //判断用户名和密码 string userName = TextBox1.Text.Trim(); bool bRet = RtxLogin.IsUserExisted(userName); //这个函数另见RtxLogin.cs源文件 if (false == bRet) { Response.Write("用户不存在"); return; } string SessionKey = RtxLogin.GetSessionKey(userName); //这个函数另见RtxLogin类 string severip = txtServerIP.Text; //RTX服务器IP地址 short serverport = Convert.ToInt16(txtAppServerPort.Text);//RTX服务器端口,8000; RtxLogin.SessionKeyLogin(severip, serverport, userName, SessionKey); //用Response对象实现RX客户端登录并打开一个新的页面(登录代码有可能改进) Response.Write("<html>" + "\r"); } public class RtxLogin { //private static RTXSAPILib.RTXSAPIRootObj RootObj; public static bool IsUserExisted(string username) { RTXSAPILib.RTXSAPIRootObj RootObj = new RTXSAPIRootObj(); RTXSAPILib.RTXSAPIUserManager UserManagerObj = RootObj.UserManager; bool bRet = true; try { bRet = UserManagerObj.IsUserExist(username); } catch (COMException ex) { bRet = false; } return bRet; } public static string GetSessionKey(string Account) //服务器端代码 { string SessionKey = ""; RTXSAPILib.RTXSAPIRootObj RootObj = new RTXSAPIRootObj(); //创建一个根对象 RTXSAPILib.RTXSAPIUserAuthObj UserAuthObj = RootObj.UserAuthObj; //创建一个用户认证对象 RootObj.ServerIP = ConfigurationManager.AppSettings["rtxServerIP"]; //设置服务器IP,"127.0.0.1" RootObj.ServerPort = Convert.ToInt16(ConfigurationManager.AppSettings["rtxServerAppPort"]); //设置Appserver端口,8006 try { SessionKey = UserAuthObj.GetSessionKey(Account); //通过用户认证对象获取SessionKey,貌似正确的帐号才能正确获取SessionKey } catch (COMException ex) { //Response.Write("<script language='javascript'>alert('ex.Message')</script>"); } return SessionKey; //返回SessionKey } public static void SessionKeyLogin(string strServerIP, short sPort, string strAccount,string strSessionKey) { RTXClient.RTXAPIClass ObjApi = new RTXAPIClass(); RTXCAPILib.IRTXCRoot RTXCRoot = (RTXCAPILib.IRTXCRoot)ObjApi.GetObject("KernalRoot"); try { RTXCRoot.LoginSessionKey(strServerIP, sPort, strAccount, strSessionKey); } catch (COMException ex) { //Response.Write("<script language='javascript'>alert('" + ex.Message + "')</script>"); } }
try { bRet = UserManagerObj.IsUserExist(username); } catch (COMException ex) { bRet = false; }