WinFrom登陆问题 WinFrom登陆的用户名都储存在什么地方了?B/S保存到Session了。那么应用程序保存到什么地方了?如果还有其他要保存的东西比如说密码等,这些都要保存到哪里?怎么调用? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 来个例子。再说Winfrom是储存在cookie吗? Form的定义中,两个变量就可以用来存放这些信息保存在全局静态类的属性里面model.GetInstance().userId = textBox1.Text; 可以写一个类不必要是静态类,但属性必须是静态的,来存放登录用户的信息。我可以给你代码! [Serializable] public static class ProfileUser { /// <summary> /// 当前登录用户名 /// </summary> private static string name; /// <summary> /// 当前用户的角色名 /// </summary> private static string roleName; /// <summary> /// 当前用户的角色码用于标识用户级别 /// </summary> private static string roleCode; /// <summary> /// 当前用户的ID /// </summary> private static string userID; #region 属性 /// <summary> /// 当前用户的角色码用于标识用户级别 /// </summary> public static string RoleCode { get { return ProfileUser.roleCode; } set { ProfileUser.roleCode = value; } } /// <summary> /// 当前用户的角色名 /// </summary> public static string RoleName { get { return ProfileUser.roleName; } set { ProfileUser.roleName = value; } } /// <summary> /// 当前登录用户名 /// </summary> public static string Name { get { return ProfileUser.name; } set { ProfileUser.name = value; } } /// <summary> /// 当前用户的ID /// </summary> public static string UserID { get { return ProfileUser.userID; } set { ProfileUser.userID = value; } } #endregion } 这个可以用界面间的传值的form1里定义个全局变量a;把要传的值给a就好了,form2 f2=new form(a);f2.show();在form2里 public string m_A; public Form2(string pA) { InitializeComponent(); m_A=pA; //m_A就是传来的值了 } 我这几天正在做一个WINFORM项目刚好写了一个保存用户信息的类 public static T GetServiceToken<T>() where T : class, new() { T token = new T(); typeof(T).InvokeMember("Authenticate", BindingFlags.SetProperty, null, token, new object[] { Program.ServiceTokenAuthenticate }, null); typeof(T).InvokeMember("UserCode", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.UserCode }, null); typeof(T).InvokeMember("BizDate", BindingFlags.SetProperty, null, token, new object[] { Program.BizDate }, null); typeof(T).InvokeMember("Language", BindingFlags.SetProperty, null, token, new object[] { Program.Language }, null); typeof(T).InvokeMember("Password", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.Password }, null); typeof(T).InvokeMember("UserID", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.UserID }, null); return token; } Form的定义中,两个变量就可以用来存放这些信息保存在全局静态类的属性里面 可以保存在cookie中;前提是保存Cookie的进程不要湮灭,这主要是针对多线程要注意的。实例:登录淘宝。 public void Fun_SignIn(string[][] loginData) { string TargetURL = "http://login.taobao.com/member/login.jhtml"; myrefining.Fun_HttpGET(TargetURL);//获取Cookie loginBytes = Fun_Arr2Bytes(loginData);//根据上面返回的页面,组织写入post myrefining.Fun_HttpPOST(TargetURL, loginBytes);//post,同时获取Cookie myrefining.Fun_SyntaxLogInfo("亲,你已经成功登录淘宝!"); }下面重点展示post1、定义部分private CookieContainer _myCookies;public CookieContainer myCookies{ get {return _myCookies;} set {_myCookies = value;}} public void Fun_HttpPOST(string PostURL, byte[] PostBytes) { HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(PostURL); httpReq.Method = "POST"; httpReq.KeepAlive = false; httpReq.ContentType = "application/x-www-form-urlencoded"; httpReq.Timeout = timeout; httpReq.CookieContainer = myCookies; httpReq.AllowAutoRedirect = true; httpReq.ContentLength = PostBytes.Length; Stream requestStream = httpReq.GetRequestStream(); requestStream.Write(PostBytes, 0, PostBytes.Length); requestStream.Close(); HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse(); if (httpRes.Cookies["_tb_token_"] != null) TBToken = httpRes.Cookies["_tb_token_"].Value; Stream responseStream = httpRes.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("GBK")); string StreamString = streamReader.ReadToEnd(); streamReader.Close(); httpRes.Close(); } timeout的值为5000,可以修改的。 myrefining,是我定义的一个类,可以多线程的。Fun_HttpPOST放在这个类中。 XML 或者 本地见一个Access数据库,XML利用序列化反序列化,然后进行加密,Access就是数据库,在对他加个密,或者做一个自定文件格式,就行QQ那样自己弄个自定义类型的文件。都可以,或者二进制,方法太多了 XML ,文件,注册表,数据库看你的用处一般是在数据库的 冰天雪地跪地求教!!!!! 分享向txt文档里一条一条的写如数据 如何提高C#插入或操作数据库的速度??? Winform 关于用 comboBox控件绑定数据库的问题 关于ArgumentException和ArgumentNullException的参数问题。 求datareader的例子 toolBar控件设置DropDownArrows属性问题! 使用应用程序配置文件的一个问题. “SDF”文件打不开啊??? 为什么??? 关于SNS 水晶报表弹出数据库登录框
再说Winfrom是储存在cookie吗?
保存在全局静态类的属性里面
model.GetInstance().userId = textBox1.Text;
[Serializable]
public static class ProfileUser
{
/// <summary>
/// 当前登录用户名
/// </summary>
private static string name;
/// <summary>
/// 当前用户的角色名
/// </summary>
private static string roleName;
/// <summary>
/// 当前用户的角色码用于标识用户级别
/// </summary>
private static string roleCode; /// <summary>
/// 当前用户的ID
/// </summary>
private static string userID;
#region 属性 /// <summary>
/// 当前用户的角色码用于标识用户级别
/// </summary>
public static string RoleCode
{
get { return ProfileUser.roleCode; }
set { ProfileUser.roleCode = value; }
} /// <summary>
/// 当前用户的角色名
/// </summary>
public static string RoleName
{
get { return ProfileUser.roleName; }
set { ProfileUser.roleName = value; }
} /// <summary>
/// 当前登录用户名
/// </summary>
public static string Name
{
get { return ProfileUser.name; }
set { ProfileUser.name = value; }
} /// <summary>
/// 当前用户的ID
/// </summary>
public static string UserID
{
get { return ProfileUser.userID; }
set { ProfileUser.userID = value; }
}
#endregion }
form1里定义个全局变量a;
把要传的值给a就好了,
form2 f2=new form(a);
f2.show();在form2里
public string m_A;
public Form2(string pA)
{
InitializeComponent();
m_A=pA; //m_A就是传来的值了
}
{
T token = new T();
typeof(T).InvokeMember("Authenticate", BindingFlags.SetProperty, null, token, new object[] { Program.ServiceTokenAuthenticate }, null);
typeof(T).InvokeMember("UserCode", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.UserCode }, null);
typeof(T).InvokeMember("BizDate", BindingFlags.SetProperty, null, token, new object[] { Program.BizDate }, null);
typeof(T).InvokeMember("Language", BindingFlags.SetProperty, null, token, new object[] { Program.Language }, null);
typeof(T).InvokeMember("Password", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.Password }, null);
typeof(T).InvokeMember("UserID", BindingFlags.SetProperty, null, token, new object[] { Program.CurrentUserInfo.UserID }, null); return token;
}
保存在全局静态类的属性里面
实例:登录淘宝。 public void Fun_SignIn(string[][] loginData)
{
string TargetURL = "http://login.taobao.com/member/login.jhtml";
myrefining.Fun_HttpGET(TargetURL);//获取Cookie
loginBytes = Fun_Arr2Bytes(loginData);//根据上面返回的页面,组织写入post
myrefining.Fun_HttpPOST(TargetURL, loginBytes);//post,同时获取Cookie
myrefining.Fun_SyntaxLogInfo("亲,你已经成功登录淘宝!");
}下面重点展示post
1、定义部分private CookieContainer _myCookies;
public CookieContainer myCookies{ get {return _myCookies;} set {_myCookies = value;}}
public void Fun_HttpPOST(string PostURL, byte[] PostBytes)
{
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(PostURL);
httpReq.Method = "POST";
httpReq.KeepAlive = false;
httpReq.ContentType = "application/x-www-form-urlencoded";
httpReq.Timeout = timeout;
httpReq.CookieContainer = myCookies;
httpReq.AllowAutoRedirect = true;
httpReq.ContentLength = PostBytes.Length;
Stream requestStream = httpReq.GetRequestStream();
requestStream.Write(PostBytes, 0, PostBytes.Length);
requestStream.Close();
HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();
if (httpRes.Cookies["_tb_token_"] != null)
TBToken = httpRes.Cookies["_tb_token_"].Value;
Stream responseStream = httpRes.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("GBK"));
string StreamString = streamReader.ReadToEnd();
streamReader.Close();
httpRes.Close();
}
Fun_HttpPOST放在这个类中。
看你的用处
一般是在数据库的