如果我用客户端向服务端发送一个Http post(其中有用户名和密码),服务器端进行处理,会在数据库(web.config已经配置好)中生成一条session记录,并向客户端返回一个sessionID,但是数据库只保存的是数据sessionID,并没有用户名和密码,如果,我客户端需要向服务申请完成该用户的订单,其中需要发送SessionId,但是服务器只验证了Session,但是服务器还是不知道用户名和密码,服务器如何完成该用户的订单?
调试欢乐多
这里面可以存用户信息
这个时候应该是空的。里面的记录可能是无用的
如果我用HttpContext.Current.Session["UserName"] = "chp845";保存用户名,下次我如何根据sessionID查找我的用户名,还有一个问题,httpwebreques怎么创送sessionID?
HttpContext.Current.Session["UserName"] = "chp845";
//HttpContext.Current.Session.SessionID;//并把sessionID返回给客户端
1.请问客户端收到SessionId,如何通过httpwebrequest把sessionId给服务器验证?
2.服务器如何根据sessionID找到UserName?
可以给个简单的例子吗?
HttpContext.Current.Session["UserName"]
就是当前的内容,无需查SessionID啊。Session是不会混淆的
如果我建立一个webApplication作为服务端:
protected void Page_Load(object sender, EventArgs e)
{
Stream inputStream = HttpContext.Current.Request.InputStream;
StreamReader reader = new StreamReader(inputStream, System.Text.Encoding.Unicode);
string responseContent = reader.ReadToEnd();
if (responseContent=="chp")
{
responseContent = HttpContext.Current.Session.SessionID;
HttpContext.Current.Session["UserName"] = "chp";
}
Response.ContentType = "text/plain";
Response.Write(resp);
}生成网页:http://localhost:3305/Default.aspx
再建一个客户端:
string postData="chp";
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strUrl);
myReq.Method = "post";
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] byte1 = encoding.GetBytes(postData);
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ReadWriteTimeout = 1000;
myReq.ContentLength = byte1.Length;
Stream newStream = myReq.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();
HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();//这里获取到了sessionid
Stream streamReq = myRes.GetResponseStream();
StreamReader reader = new StreamReader(streamReq, System.Text.Encoding.UTF8);
string s = reader.ReadToEnd();
streamReq.Close();
reader.Close();1.我客户端如何把从服务器获得sessionID放在http header中返回给服务器?(可以给个简单的代码)
2.服务器如何根据客户端传送的sessionID,找到相应的session对象,并找到其中的值?
那如果。多个客户端发出请求。还不会发生混乱吗?