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 7883843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:38:33+00:00 2026-06-03T04:38:33+00:00

I’m trying to display a web page which requires one to be logged in

  • 0

I’m trying to display a web page which requires one to be logged in first.
I’m using HttpWebRequest/Response objects to accomplish the logging in part, by collecting the session and authorization cookies in the background.

After logging in, a HttpWebResponse object returns to me the HTML page that I want to show the user via the WebBrowser control, so I know I have the right set of session/authorization cookies to get to the desired web page.

Having the CookieContainer properly populated with relevant cookies, I set the WebBrowser.DocumentText property to a prepared HTML which contains a GET command to the web address I’m trying to display. The browser pops-up trying to render the prepared HTML and I get a server error relating to missing cookies, I assume.

When I try to set WebBrowser.Document.Cookie prior to calling the DocumentText property, in the debugger I’m seeing, that the Cookie property always remains null after trying to set it to a string of the form “cookName=cookValue; cookName=cookValue;”.

Why does the Cookie property reject the cookies string I’m passing it? Does this have something to do with HttpOnly cookies? Is my cookie string incorrectly formatted? Am I trying to set the Cookie property at the wrong time?

I did the WebBrowser.Navigate(“about:blank”) call, which seems to be required to properly initialize the WebBrowser object.

  • 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-06-03T04:38:34+00:00Added an answer on June 3, 2026 at 4:38 am

    Here is what worked for me:

      using System.Runtime.InteropServices;
    
      [DllImport("wininet.dll",CharSet = CharSet.Auto, SetLastError = true)]
      public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
    
      //'CookieCollection' was populated using HttpWebRequest/Response calls
      int i=0;
      InternetSetCookie("https://www.myurl.com/", null, CookieCollection[i++].ToString() + "; expires = Sun, 01-Jan-2013 00:00:00 GMT");
      //repeat for however many cookies you've got
    
      browser.Navigate("https://www.myurl.com/tools/..../Index.aspx?t=someValue", true);
      //or
      browser.DocumentText = someHtml;
    

    Notes:

    1) Without including the “expires” value the InternetSetCookie call did not work despite returning ‘true’. The “expires” value turns the cookie into a persistent cookie as opposed to a session only cookie.

    2) ‘browser.Navigate(“about:blank”);’ does not seem to be required. I was able to get at my page with and without this statement.

    3) browser.Document.Cookie never worked for me (always null), no matter what I threw at it. And I’ve tried a lot of different strings, including the one passed into the third parameter of InternetSetCookie.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small

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.