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

  • Home
  • SEARCH
  • 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 8113119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:43:34+00:00 2026-06-06T02:43:34+00:00

I am trying to access a webpage on a same domain / same asp.net

  • 0

I am trying to access a webpage on a same domain / same asp.net application, that is password protected. Credentials are the same both for webpage firing this call and webpage being accessed.

Here is the code, and I don’t know why I always end up with a login form html code?

using (WebClient client = new WebClient())
{
    client.QueryString.Add("ID", "1040"); //add parameters
    //client.Credentials = CredentialCache.DefaultCredentials;
    //I tried to add credentials like this
    client.Credentials = new NetworkCredential("username", "password");

    string htmlCode = client.DownloadString("http://domain.loc/testpage.aspx");
}
  • 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-06T02:43:36+00:00Added an answer on June 6, 2026 at 2:43 am

    I suspect that the web page that you are trying to access uses Forms Authentication. This means that you will have to provide a valid authentication cookie if you want to be able to access protected resources. And in order to obtain a valid authentication cookie you will have to first authenticate yourself by sending a POST request to the LogOn page which emits the cookie. Once you retrieve the cookie you will be able to send it along on subsequent requests on protected resources. You should also note that out of the box WebClient doesn’t support cookies. For this reason you could write a custom cookie aware web client:

    public class CookieAwareWebClient : WebClient
    {
        public CookieAwareWebClient()
        {
            CookieContainer = new CookieContainer();
        }
        public CookieContainer CookieContainer { get; private set; }
    
        protected override WebRequest GetWebRequest(Uri address)
        {
            var request = (HttpWebRequest)base.GetWebRequest(address);
            request.CookieContainer = CookieContainer;
            return request;
        }
    }
    

    Now you could use this client to fire off the 2 requests:

    using (var client = new CookieAwareWebClient())
    {
        var values = new NameValueCollection
        {
            { "username", "john" },
            { "password", "secret" },
        };
        client.UploadValues("http://domain.loc/logon.aspx", values);
    
        // If the previous call succeeded we now have a valid authentication cookie
        // so we could download the protected page
        string result = client.DownloadString("http://domain.loc/testpage.aspx");
    }
    

    Obviously due to the ViewState crapiness of ASP.NET you might need to send a couple of other parameters along your logon request. Here’s what you could do: authenticate in a web browser and look with FireBug the exact parameters and headers that need to be sent.

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

Sidebar

Related Questions

I am trying to access a webpage through ASP.NET using the NetworkCredential class. However
I am trying to get the contents of a webpage that requires a password
I am trying to create a Java Application that retrieves information from a webpage.
I am developing an application using asp.net 2.0 (C#), in which I am trying
I am just trying to access a webservice or any webpage for that matter
I'm trying to make a program that fetches information from this webpage, www.sio.no ,
The webpage that I'm trying to access is sending back a 403 error. I's
I am calling an ASP.net application that has an exposed JSON web service interface.
I'm trying to access a secure webpage on one of our servers. The webpage
I am trying to use C# to access the content of a webpage. For

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.