.htaccess and NetworkCredentials question

  • Thread starter Thread starter Matthew Law
  • Start date Start date
M

Matthew Law

Hi,

I'm writing a C# app to retrieve a web page which is protected by a
..htaccess file. I've been trying various things for a while and
continue to get a network exception:

The remote server returned an error: (401) Unauthorized.

Can anyone tell me where I am going wrong? My current code effort is:

....
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(URL);

myReq.MaximumAutomaticRedirections = 4;
myReq.MaximumResponseHeadersLength = 4;

myReq.Credentials = new System.Net.NetworkCredential("myuser",
"letmein");

....

Many thanks in advance,

Matt.
 
I'm writing a C# app to retrieve a web page which is protected by a
.htaccess file. I've been trying various things for a while and
continue to get a network exception:

The keyword of yout text is "protected by .htaccess". If a derective like
"Deny from all" exist in .htaccess in the folder from wich you want to get
the page, you'll get nothing but 401. Apache won't allow you to view any
page you have no viewing rights for.

Gaidar
 
Gaidar said:
The keyword of yout text is "protected by .htaccess". If a derective like
"Deny from all" exist in .htaccess in the folder from wich you want to get
the page, you'll get nothing but 401. Apache won't allow you to view any
page you have no viewing rights for.

Gaidar

Its safe to say that he already knows that and he has the username and
password.
 
I know the .htaccess works because I can use the username and password
to gain access through a browser.

I just need to get the code to do the same.
 
Back
Top