Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Maintain Session Variables using WebRequest .

How to Maintain Session Variables using WebRequest .

Scheduled Pinned Locked Moved ASP.NET
htmltutorialquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rana Muhammad Javed Khan
    wrote on last edited by
    #1

    I am using WebRequest to Get the HTML of specific URL(of same application) which works fine but not the session variables are not being sent. If any one has used this please let me know?:zzz:

    S 1 Reply Last reply
    0
    • R Rana Muhammad Javed Khan

      I am using WebRequest to Get the HTML of specific URL(of same application) which works fine but not the session variables are not being sent. If any one has used this please let me know?:zzz:

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      Are you using HttpRequest to get HTML page ?

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      R 1 Reply Last reply
      0
      • S Sandeep Akhare

        Are you using HttpRequest to get HTML page ?

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

        R Offline
        R Offline
        Rana Muhammad Javed Khan
        wrote on last edited by
        #3

        I am using WebRequest and here is the code: Dim _WebReq As WebRequest Dim _WebResp As WebResponse Dim _StreamReader As StreamReader Dim strHTML As String _WebReq = _WebReq.Create(strURL) _WebResp = _WebReq.GetResponse _StreamReader = New StreamReader(_WebResp.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd Thanks

        S 1 Reply Last reply
        0
        • R Rana Muhammad Javed Khan

          I am using WebRequest and here is the code: Dim _WebReq As WebRequest Dim _WebResp As WebResponse Dim _StreamReader As StreamReader Dim strHTML As String _WebReq = _WebReq.Create(strURL) _WebResp = _WebReq.GetResponse _StreamReader = New StreamReader(_WebResp.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd Thanks

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          Why don't you use Http Web Request using that u can set and get cookies also HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]); request.CookieContainer = new CookieContainer(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // Print the properties of each cookie. foreach (Cookie cook in response.Cookies) { Console.WriteLine("Cookie:"); Console.WriteLine("{0} = {1}", cook.Name, cook.Value); Console.WriteLine("Domain: {0}", cook.Domain); Console.WriteLine("Path: {0}", cook.Path); Console.WriteLine("Port: {0}", cook.Port); Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp); Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired); Console.WriteLine("Don't save: {0}", cook.Discard); Console.WriteLine("Comment: {0}", cook.Comment); Console.WriteLine("Uri for comments: {0}", cook.CommentUri); Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie. Console.WriteLine ("String: {0}", cook.ToString()); }

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          R 1 Reply Last reply
          0
          • S Sandeep Akhare

            Why don't you use Http Web Request using that u can set and get cookies also HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]); request.CookieContainer = new CookieContainer(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // Print the properties of each cookie. foreach (Cookie cook in response.Cookies) { Console.WriteLine("Cookie:"); Console.WriteLine("{0} = {1}", cook.Name, cook.Value); Console.WriteLine("Domain: {0}", cook.Domain); Console.WriteLine("Path: {0}", cook.Path); Console.WriteLine("Port: {0}", cook.Port); Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp); Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired); Console.WriteLine("Don't save: {0}", cook.Discard); Console.WriteLine("Comment: {0}", cook.Comment); Console.WriteLine("Uri for comments: {0}", cook.CommentUri); Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie. Console.WriteLine ("String: {0}", cook.ToString()); }

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

            R Offline
            R Offline
            Rana Muhammad Javed Khan
            wrote on last edited by
            #5

            Please look into this code is there any mistake in it? i am not being able to get session values? Dim _HttpWebRequest As HttpWebRequest = HttpWebRequest.Create(strURL) _HttpWebRequest.CookieContainer = New CookieContainer Dim _HttpWebResponse As HttpWebResponse _HttpWebResponse = _HttpWebRequest.GetResponse Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next Dim _StreamReader As StreamReader ' Process the URL and Get HTML _StreamReader = New StreamReader(_HttpWebResponse.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd

            S 1 Reply Last reply
            0
            • R Rana Muhammad Javed Khan

              Please look into this code is there any mistake in it? i am not being able to get session values? Dim _HttpWebRequest As HttpWebRequest = HttpWebRequest.Create(strURL) _HttpWebRequest.CookieContainer = New CookieContainer Dim _HttpWebResponse As HttpWebResponse _HttpWebResponse = _HttpWebRequest.GetResponse Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next Dim _StreamReader As StreamReader ' Process the URL and Get HTML _StreamReader = New StreamReader(_HttpWebResponse.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #6

              M Javed Khan wrote:

              Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next

              Here you are adding the cookie

              Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

              R 1 Reply Last reply
              0
              • S Sandeep Akhare

                M Javed Khan wrote:

                Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next

                Here you are adding the cookie

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                R Offline
                R Offline
                Rana Muhammad Javed Khan
                wrote on last edited by
                #7

                I have removed this but still session values are not being used by HTTPWebRequest :(.

                S 1 Reply Last reply
                0
                • R Rana Muhammad Javed Khan

                  I have removed this but still session values are not being used by HTTPWebRequest :(.

                  S Offline
                  S Offline
                  Sandeep Akhare
                  wrote on last edited by
                  #8

                  I am still asking you what you want to do ? As session varaibles are store at the server side you can't get them using response .. How can you read the session varaibles ? You can read cookies are those are store at the client side

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                  R 1 Reply Last reply
                  0
                  • S Sandeep Akhare

                    I am still asking you what you want to do ? As session varaibles are store at the server side you can't get them using response .. How can you read the session varaibles ? You can read cookies are those are store at the client side

                    Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                    R Offline
                    R Offline
                    Rana Muhammad Javed Khan
                    wrote on last edited by
                    #9

                    Sorry for confussion!!! let me explain it to u! Let suppose i have URL = "http://www.some.com" Now in it i have a Grid which depends on some session variables. Now when i use Response.Redirect(URL) the grid reterives the data on the basis of session variables. but when i use HTTPWebRequest to get the HTML which is generated for that URL grid doesn't reterives session values. I have to get the execute the URL on the Server and Get the Generated HTML. Hope u will got it!!!

                    S 1 Reply Last reply
                    0
                    • R Rana Muhammad Javed Khan

                      Sorry for confussion!!! let me explain it to u! Let suppose i have URL = "http://www.some.com" Now in it i have a Grid which depends on some session variables. Now when i use Response.Redirect(URL) the grid reterives the data on the basis of session variables. but when i use HTTPWebRequest to get the HTML which is generated for that URL grid doesn't reterives session values. I have to get the execute the URL on the Server and Get the Generated HTML. Hope u will got it!!!

                      S Offline
                      S Offline
                      Sandeep Akhare
                      wrote on last edited by
                      #10

                      Sorry but i think you can't do that as Session is store at server side you are accessing the aaplication from the URL Why don't you use query string instead of session varaibles to retrive the data. As per my understanding there is one application that have one url After user enters into website Server side session are get created and store Using this Session values data is coming in Datagrid .

                      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups