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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:09:06+00:00 2026-06-16T09:09:06+00:00

I have a website running asp.net 2.0 with url authentication. There is a protected

  • 0

I have a website running asp.net 2.0 with url authentication. There is a protected region of the website that requires users to log in to gain access to protected files. Is it possible to do the same thing using a System.Net.WebClient object to download a file in the protected area?

If you try to manually type in the url to a protected file, resource, page, etc it forwards you to the login page. I also get the html for the login page inside of “protectedFile.zip” whenever I execute the code below.

public void test()
{
        try
        {
            using (var client = new CookieAwareWebClient())
            {
                //Not sure which name values to include, so I used what was in the post output in Firefox's firebug.
                var values = new NameValueCollection
            {
                { "ctl00$ContentPlaceHolder1$Login1$UserName", "testUsername" },
                { "ctl00$ContentPlaceHolder1$Login1$Password", "testPassword" }
            };
                retValue = client.UploadValues("www.test.com/login.aspx", values);
                //retValue contains the login page?
                Console.WriteLine(ASCIIEncoding.ASCII.GetString(retValue));
                // If the previous call succeeded we now have a valid authentication cookie??
                client.DownloadFile("www.test.com/protected/protectedFile.zip", "protectedFile.zip");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            Console.WriteLine(ASCIIEncoding.ASCII.GetString(retValue));
        }
}

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;
    }
}

I have looked at the following related questions but none of them have a final solution that I can understand.

asp.net Download files from protected server

How do I authenticate a WebClient request?

C# WebClient Log onto Website

WebClient accessing page with credentials

Can't login into asp.net website with WebClient

Any help would be appreciated!

  • 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-16T09:09:07+00:00Added an answer on June 16, 2026 at 9:09 am

    If you are trying to “spoof” an ASP.Net Web Forms Postback, you will run into issues that will prevent you from doing so. You have to deal with VIEWSTATE and EVENTVALIDATION

    The __EVENTVALIDATION hidden field is a security measure new to ASP.NET 2.0. The feature prevents unauthorized requests sent by potentially malicious users from the client. To ensure that each and every postback and callback event originates from the expected user interface elements, the page adds an extra layer of validation on events.

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

Sidebar

Related Questions

I have a website running a basic ASP.NET application that is mostly used from
I have a website that a converted into a web application running ASP.NET webforms.
I have a ASP.NET 3.5 website running on Windows Server 2003 and I'm using
I have this ASP.NET/SQLServer2005 website running on a production server (Win2003, QuadCore, 4GB). The
I have an ASP.NET 4 WebForms website running off IIS 7, we have three
I have coded up an ASP.NET website and running on win'08 (remotely hosted). The
ASP.NET newbie here I have coded up an ASP.NET website and running on win'08
I have a ASP.NET Website (.NET 2 IIS 5.1) running on machine A with
I have an asp.net website in my production server which running fine now. Now
i have an asp.net website http://www.site.com . This web app is also running on

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.