WebClient.DownloadFile creates an error ??

Discussion in 'ASP .Net' started by Chris, Jul 13, 2004.

  1. Chris

    Chris Guest

    Hi,

    I try to download a file using the following :

    WebClient client = new WebClient();
    client.Credentials = new NetworkCredential("Administrator",
    "test","MYPC");
    client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");

    but I get an error :
    The remote server returned an error: (403) Forbidden.

    how come ?

    thanks
    Chris

    (I'm executing everything on my machine where I'm logged in as
    'Administrator')
     
    Chris, Jul 13, 2004
    #1
    1. Advertising

  2. Chris

    Patrice Guest

    What if you point your browser to http://localhost/afile.txt ? (in
    partiuclar are you prompted with the domaion name and is the domain name
    correct ?)


    --

    "Chris" <> a écrit dans le message de
    news:4tPIc.184017$-ops.be...
    > Hi,
    >
    > I try to download a file using the following :
    >
    > WebClient client = new WebClient();
    > client.Credentials = new NetworkCredential("Administrator",
    > "test","MYPC");
    > client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");
    >
    > but I get an error :
    > The remote server returned an error: (403) Forbidden.
    >
    > how come ?
    >
    > thanks
    > Chris
    >
    > (I'm executing everything on my machine where I'm logged in as
    > 'Administrator')
    >
    >
    >
     
    Patrice, Jul 13, 2004
    #2
    1. Advertising

  3. Chris

    Patrice Guest

    Hummm, just to make sure, do you have some code that actually uses the
    credentials you created ? If not see the "Credentials" property :
    http://msdn.microsoft.com/library/d...fsystemnetwebclientclassdownloadfiletopic.asp

    If you have some additional code you may want to post all the relevant
    code...

    Patrice

    --

    "Chris" <> a écrit dans le message de
    news:4tPIc.184017$-ops.be...
    > Hi,
    >
    > I try to download a file using the following :
    >
    > WebClient client = new WebClient();
    > client.Credentials = new NetworkCredential("Administrator",
    > "test","MYPC");
    > client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");
    >
    > but I get an error :
    > The remote server returned an error: (403) Forbidden.
    >
    > how come ?
    >
    > thanks
    > Chris
    >
    > (I'm executing everything on my machine where I'm logged in as
    > 'Administrator')
    >
    >
    >
     
    Patrice, Jul 13, 2004
    #3
  4. Chris

    Chris Guest

    Hi Patrice,

    actually I just want to download a file for which I have the url. (The file
    is not visualized nowhere in the browser)

    what are the possibilities ?

    thanks
    Chris


    "Patrice" <> wrote in message
    news:...
    > What if you point your browser to http://localhost/afile.txt ? (in
    > partiuclar are you prompted with the domaion name and is the domain name
    > correct ?)
    >
    >
    > --
    >
    > "Chris" <> a écrit dans le message de
    > news:4tPIc.184017$-ops.be...
    > > Hi,
    > >
    > > I try to download a file using the following :
    > >
    > > WebClient client = new WebClient();
    > > client.Credentials = new NetworkCredential("Administrator",
    > > "test","MYPC");
    > > client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");
    > >
    > > but I get an error :
    > > The remote server returned an error: (403) Forbidden.
    > >
    > > how come ?
    > >
    > > thanks
    > > Chris
    > >
    > > (I'm executing everything on my machine where I'm logged in as
    > > 'Administrator')
    > >
    > >
    > >

    >
    >
     
    Chris, Jul 13, 2004
    #4
  5. Chris

    Patrice Guest

    I unsderstood. Just wanted to know it it works manually especially with this
    exact credentials.

    Check also my other post (did you omitted the code that uses the credentials
    or is this code missing from your code ?)

    --

    "Chris" <> a écrit dans le message de
    news:nUPIc.184040$-ops.be...
    > Hi Patrice,
    >
    > actually I just want to download a file for which I have the url. (The

    file
    > is not visualized nowhere in the browser)
    >
    > what are the possibilities ?
    >
    > thanks
    > Chris
    >
    >
    > "Patrice" <> wrote in message
    > news:...
    > > What if you point your browser to http://localhost/afile.txt ? (in
    > > partiuclar are you prompted with the domaion name and is the domain name
    > > correct ?)
    > >
    > >
    > > --
    > >
    > > "Chris" <> a écrit dans le message de
    > > news:4tPIc.184017$-ops.be...
    > > > Hi,
    > > >
    > > > I try to download a file using the following :
    > > >
    > > > WebClient client = new WebClient();
    > > > client.Credentials = new NetworkCredential("Administrator",
    > > > "test","MYPC");
    > > > client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");
    > > >
    > > > but I get an error :
    > > > The remote server returned an error: (403) Forbidden.
    > > >
    > > > how come ?
    > > >
    > > > thanks
    > > > Chris
    > > >
    > > > (I'm executing everything on my machine where I'm logged in as
    > > > 'Administrator')
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Patrice, Jul 13, 2004
    #5
  6. Chris

    Chris Guest

    Without the credential-code ...
    client.Credentials = new NetworkCredential("Administrator",
    "nav01ils","PC-
    WIN2000");

    .... do I get the error
    The remote server returned an error: (401) Unauthorized

    With the credential-code do I get the error
    The remote server returned an error: (403) Forbidden.


    "Patrice" <> wrote in message
    news:...
    > I unsderstood. Just wanted to know it it works manually especially with

    this
    > exact credentials.
    >
    > Check also my other post (did you omitted the code that uses the

    credentials
    > or is this code missing from your code ?)
    >
    > --
    >
    > "Chris" <> a écrit dans le message de
    > news:nUPIc.184040$-ops.be...
    > > Hi Patrice,
    > >
    > > actually I just want to download a file for which I have the url. (The

    > file
    > > is not visualized nowhere in the browser)
    > >
    > > what are the possibilities ?
    > >
    > > thanks
    > > Chris
    > >
    > >
    > > "Patrice" <> wrote in message
    > > news:...
    > > > What if you point your browser to http://localhost/afile.txt ? (in
    > > > partiuclar are you prompted with the domaion name and is the domain

    name
    > > > correct ?)
    > > >
    > > >
    > > > --
    > > >
    > > > "Chris" <> a écrit dans le message de
    > > > news:4tPIc.184017$-ops.be...
    > > > > Hi,
    > > > >
    > > > > I try to download a file using the following :
    > > > >
    > > > > WebClient client = new WebClient();
    > > > > client.Credentials = new NetworkCredential("Administrator",
    > > > > "test","MYPC");
    > > > > client.DownloadFile("http://localhost/afile.txt",

    "c:\\test.txt");
    > > > >
    > > > > but I get an error :
    > > > > The remote server returned an error: (403) Forbidden.
    > > > >
    > > > > how come ?
    > > > >
    > > > > thanks
    > > > > Chris
    > > > >
    > > > > (I'm executing everything on my machine where I'm logged in as
    > > > > 'Administrator')
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Chris, Jul 13, 2004
    #6
  7. Chris

    Patrice Guest

    And are you able to access this file when using a browser and entering
    manually these credentials ? This is to find out if the problem is rather in
    the code or if there is something wrong regarding the security settings.

    Also the code I saw uses generally a CredentialCache. In particular it
    allows to specify the authentication method to use. I believe it could miss
    from your code :
    (taken from the doc) :

    CredentialCache myCache = new CredentialCache();

    myCache.Add(new Uri("http://www.contoso.com/"),"Basic",new
    NetworkCredential(UserName,SecurelyStoredPassword));
    myCache.Add(new Uri("http://www.contoso.com/"),"Digest", new
    NetworkCredential(UserName,SecurelyStoredPassword,Domain));

    wReq.Credentials = myCache;

    See :
    http://msdn.microsoft.com/library/d...rlrfsystemnetcredentialcacheclassaddtopic.asp
    for details...

    So I would check first :
    - security is ok, I can access the ressource manually with these exact same
    credentials
    - then I would try to use a credential cache to specifiy the URI as well as
    the authentication method used
    - if it wokrs I woukld then, eventually try to use directly the Credentials
    (I'm really not sure what the .NET library does when these informations
    can't be found from the CredentialCache).

    Patrice
    --

    "Chris" <> a écrit dans le message de
    news:koQIc.184055$-ops.be...
    > Without the credential-code ...
    > client.Credentials = new NetworkCredential("Administrator",
    > "nav01ils","PC-
    > WIN2000");
    >
    > ... do I get the error
    > The remote server returned an error: (401) Unauthorized
    >
    > With the credential-code do I get the error
    > The remote server returned an error: (403) Forbidden.
    >
    >
    > "Patrice" <> wrote in message
    > news:...
    > > I unsderstood. Just wanted to know it it works manually especially with

    > this
    > > exact credentials.
    > >
    > > Check also my other post (did you omitted the code that uses the

    > credentials
    > > or is this code missing from your code ?)
    > >
    > > --
    > >
    > > "Chris" <> a écrit dans le message de
    > > news:nUPIc.184040$-ops.be...
    > > > Hi Patrice,
    > > >
    > > > actually I just want to download a file for which I have the url. (The

    > > file
    > > > is not visualized nowhere in the browser)
    > > >
    > > > what are the possibilities ?
    > > >
    > > > thanks
    > > > Chris
    > > >
    > > >
    > > > "Patrice" <> wrote in message
    > > > news:...
    > > > > What if you point your browser to http://localhost/afile.txt ? (in
    > > > > partiuclar are you prompted with the domaion name and is the domain

    > name
    > > > > correct ?)
    > > > >
    > > > >
    > > > > --
    > > > >
    > > > > "Chris" <> a écrit dans le message de
    > > > > news:4tPIc.184017$-ops.be...
    > > > > > Hi,
    > > > > >
    > > > > > I try to download a file using the following :
    > > > > >
    > > > > > WebClient client = new WebClient();
    > > > > > client.Credentials = new NetworkCredential("Administrator",
    > > > > > "test","MYPC");
    > > > > > client.DownloadFile("http://localhost/afile.txt",

    > "c:\\test.txt");
    > > > > >
    > > > > > but I get an error :
    > > > > > The remote server returned an error: (403) Forbidden.
    > > > > >
    > > > > > how come ?
    > > > > >
    > > > > > thanks
    > > > > > Chris
    > > > > >
    > > > > > (I'm executing everything on my machine where I'm logged in as
    > > > > > 'Administrator')
    > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Patrice, Jul 13, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cheri Elkin

    WebClient DownloadFile problem

    Cheri Elkin, Nov 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,849
    Jon Paugh
    Nov 20, 2003
  2. =?Utf-8?B?REVXcmlnaHRfQ0E=?=

    WebClient.DownloadFile only see's Local????

    =?Utf-8?B?REVXcmlnaHRfQ0E=?=, May 25, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    2,669
    Steven Cheng[MSFT]
    Jun 6, 2005
  3. Replies:
    1
    Views:
    962
    Joerg Jooss
    Oct 22, 2005
  4. A.M-SG
    Replies:
    2
    Views:
    5,436
    Kspatel
    Aug 31, 2009
  5. Purva
    Replies:
    4
    Views:
    2,926
Loading...

Share This Page