Re: WebClient and windows authentication

  • Thread starter Thread starter Nick Malik
  • Start date Start date
N

Nick Malik

Personally, I use webrequest, not web client. However, the credential part
should look like the following...

// Create a webrequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Credentials = CredentialCache.DefaultCredential;

See
http://msdn.microsoft.com/library/d.../cpconusinginternetrequestresponseclasses.asp

--- Nick

Danny Hille said:
Hi im trying to download some images using WebClient.DownloadData

System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredentia(sNme,sPwd,sDom);
byte [] bytes = wc.DownloadData(txtURL.Text);

this raises an exception:

Request for the permission of type System.Net.WebPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
 
Sorry Nick but thats not what i want, i don't want to authenticate as current logged in user, i want to specify username, password and domain. But eaven if i try using the CredentialCache i still get the same error.

Nick Malik said:
Personally, I use webrequest, not web client. However, the credential part
should look like the following...

// Create a webrequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Credentials = CredentialCache.DefaultCredential;

See
http://msdn.microsoft.com/library/d.../cpconusinginternetrequestresponseclasses.asp

--- Nick

Danny Hille said:
Hi im trying to download some images using WebClient.DownloadData

System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredentia(sNme,sPwd,sDom);
byte [] bytes = wc.DownloadData(txtURL.Text);

this raises an exception:

Request for the permission of type System.Net.WebPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
any ideas how to solve this?

NB. I can'not use basic authentication only windows-auth.

Thanks in advance
 
Did you set PreAuthenticate?

// Create a new webrequest to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create(url);

// Set 'Preauthenticate' property to true. Credentials will be
sent with the request.
myWebRequest.PreAuthenticate=true;

// Create a New 'NetworkCredential' object.
NetworkCredential networkCredential=new
NetworkCredential(UserName,Password);

// Associate the 'NetworkCredential' object with the
'WebRequest' object.
myWebRequest.Credentials=networkCredential;

// Assign the response object of 'WebRequest' to a 'WebResponse'
variable.
WebResponse myWebResponse=myWebRequest.GetResponse();

Danny Hille said:
Sorry Nick but thats not what i want, i don't want to authenticate as
current logged in user, i want to specify username, password and domain. But
eaven if i try using the CredentialCache i still get the same error.
Nick Malik said:
Personally, I use webrequest, not web client. However, the credential part
should look like the following...

// Create a webrequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Credentials = CredentialCache.DefaultCredential;

See
http://msdn.microsoft.com/library/d.../cpconusinginternetrequestresponseclasses.asp

--- Nick

Danny Hille said:
Hi im trying to download some images using WebClient.DownloadData

System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredentia(sNme,sPwd,sDom);
byte [] bytes = wc.DownloadData(txtURL.Text);

this raises an exception:

Request for the permission of type System.Net.WebPermission, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
any ideas how to solve this?

NB. I can'not use basic authentication only windows-auth.

Thanks in advance
 
Back
Top