locked
Passing session variable in HttpWebRequest object RRS feed

  • Question

  • Hi,

    Here is my situation,

    I want to retrieve the html code form a page  (just the html) using HttpWebRequest and HttpWebResponse objects.

    Let's say I have a page "A" with a button on it and I want  retrieve the html from page "B" after click in this button, but page "B" is expecting a session variable (session["UserID"]) and in case that this variable is null redirect to "C".

    here is my code in page "A"

    Session["UserId"] = "user";
                string html;
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:52212/C.aspx");
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                html = reader.ReadToEnd();
                reader.Close();
                response.Close();

    here is my code in page "B"

    if (Session["UserId"] != null)
                {
                    Label1.Text = Session["UserId"].ToString();
                }
                else
                {
                    Response.Redirect("C.aspx");
                }

    When I run this the http variable has the html code from "C" because (Session["UserId"] = null)

    My question is How can I pass the session variable with the HttpWebRequest that way when "B" check for Session["UserId"] it will exist

    Thanks in advance

     

    Thursday, October 6, 2011 8:59 PM

Answers

  • Hi peterposnag,

    We discuss SQL Server Reporting Services related issues in this forum. I recommend you that post the question in .NET Development forum. It is appropriate and more experts will assist you.

    .NET Development forum: http://social.msdn.microsoft.com/Forums/da-DK/category/netdevelopment

    Thanks,
    Bin Long
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Elvis Long Wednesday, October 19, 2011 7:27 AM
    Tuesday, October 11, 2011 3:24 AM