我编写一个webserver程序:
HttpContext.Current.Session["UserName"] = "chp845";
//HttpContext.Current.Session.SessionID;//并把sessionID返回给客户端
1.请问客户端收到SessionId,如何通过httpwebrequest把sessionId给服务器验证?
2.服务器如何根据sessionID找到UserName?

解决方案 »

  1.   

    1.客户端把SessionID存入 Cookie里面了,当一个用户提交了表单时,浏览器会将用户的SessionID自动附加在HTTP头信息中,(这是浏览器的自动功能,用户不会察觉到)。
    2.服务器在内置的Session对象里面依据唯一的SessionID就定位到某个浏览器的Session,然后根据UserName就得到所属数值。
      

  2.   

    那我用httpwebrequest怎么附加sessionid?
    还有,我服务端如何获取发过来的sessionID?
      

  3.   

    服务器端 this.Session.SessionID ,至于浏览器怎么附加,那是浏览器的功能,不用管的。
      

  4.   

    我建立的一个webapp:
    namespace WebApplication3
    {
        public partial class _Default : System.Web.UI.Page
        {
            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();
                string resp = Class2.Disopose(responseContent);
                Response.ContentType = "text/plain";
                Response.Write(resp);    
            }
        }
    我需要获取客户端发过来的sessionID,所以我要知道怎么附加的呀?
    }
      

  5.   

    网页提交到服务端,然后是服务端进行验证的,具体session值是存储在服务端的
      

  6.   

    是不是不允许根据sessionid直接获取session对象,是sessionid放在cookie中通过验证