Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5965409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:37:32+00:00 2026-05-22T19:37:32+00:00

Using WebRequest and WebResponse , I’m able to post login information to an external

  • 0

Using WebRequest and WebResponse, I’m able to post login information to an external site and receive the cookie in Response.Cookies and in my CookieContainer. I know this is working because in the same procedure, I can request a different page and not be redirected to the login page. This cookie is what allows me to stay on the site without logging in with each page view.

I’m now trying to add the cookie to the client’s browser using Response.Cookies.Add(httpCookie);

However, it’s only persisting until the end of the procedure. Reload the page, and the cookie is no longer available.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:37:33+00:00Added an answer on May 22, 2026 at 7:37 pm

    The cookies you receive from a WebResponse from an external site cannot be passed onto your own client’s browser. This is because of the inherent security limitations of the cookie model: browsers do not support having one domain set cookies for another domain.

    This may appear to work until the end of the current request since you are just reading from the HttpCookieCollection which you just added the cookie to. This collection will persist until the current HTTP request ends.

    However, to be honest, I’m not sure how you’re able to get this far at all since the the System.Net.HttpWebResponse and CookieContainer use System.Net.Cookie, while the Response.Cookies collection uses System.Web.HttpCookie.

    Anyway, your best bet here is probably to store the value of the cookie you got in the WebResponse into your own cookie that you send to the browser. Then, on future requests, read your own cookie, construct a new Cookie for the external site, and add it to the CookieContainer manually.

    Here is some pseudocode, assuming that the cookie the external site is looking for is named “sessionKey” and we use “myCookie” for the name the cookie we send to our client’s browser:

    public ActionResult MyAction()
    {
        var container = new CookieContainer();
    
        if (Request.Cookies["myCookie"] != null)
        {
             // browser has passed in "myCookie".
             // use this to create the "sessionKey" cookie to send.
             var cookie = new System.Net.Cookie("sessionKey",
                 Request.Cookies["myCookie"].Value, "/", "external-site.com");
    
             container.Add(cookie);
        }
    
        HttpWebRequest request;
        HttpWebResponse response;
    
        // initialize the request.
        // ...
    
        // make sure we're using our cookie container.
        request.CookieContainer = container;
    
        // execute the request and get the response.
        response = request.GetResponse();
    
        // send a cookie, "myCookie", to the browser.
        // it will contain the value of the "sessionKey" cookie.
        Response.Cookies["myCookie"].Value = response.Cookies["sessionKey"].Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 20000; using (WebResponse response = request.GetResponse()) using (var
I'm trying to perform a POST to a site using a WebRequest in C#.
using (WebResponse response = webRequest.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream())) { string
I have some code: WebRequest request = HttpWebRequest.Create(url); WebResponse response = request.GetResponse(); using (System.IO.StreamReader
Using WebRequest I want to know if I get a 302 Moved Temporarily response
Using WebRequest How to POST things, Should I use GetRequestStream? and how to format
I originally used WebRequest and WebResponse to sent Http Post Messages. Always I got
I'm doing https web requests in silverlight using WebRequest/WebResponse framework classes. Problem is: I
My application often fetch data from a webpage using WebRequest, but it isn't possible
Dim myRequest As System.Net.WebRequest = System.Net.WebRequest.Create(url) Dim myResponse As System.Net.WebResponse = myRequest.GetResponse() Dim rssStream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.