Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Network credentials not taking

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
I have an ASP.net 3.5 app that will attempt to connect to an internal webpage to make sure it is accepting request.

I need to pass a user id because this process is a service and the user running the service may not have access to that page if Windows Authenication is being used.

I have the following code which takes a user account (domain\id and password) from a database, creates a NetworkCredential object sets the HttpRequest.Credentials to this new object. The problem is i never fail even when I pass-in an invalid user account.
Code:
HttpWebRequest lwhwrWebRequestObject;
lwhwrWebRequestObject = (HttpWebRequest)HttpWebRequest.Create(lstrURL);
NetworkCredential nc = new NetworkCredential(lstrCredUserName, lstrCredPassword, lstrCredDomain);
CredentialCache cc = new CredentialCache();
cc.Add(new System.Uri(lstrURL), "Basic", nc);
lwhwrWebRequestObject.Credentials = cc;
lwhwrWebRequestObject.GetResponse(); // Returns successfully everytime.  I would expect an error if the account is not correct.

If feels like its use the default creds no matter what I do.

Any help is appreciated.
 
What do you mean by "returns successful"? You will always get a response, it's the contents of the response that will inform you of success or failure. You can check the Response.StatusCode & Response.StatusDescription to determine the results.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks J,
I would expect a webexception for a 401 or a 404 error code? Thats what I would expect if my credentials are not valid. Am I thinking incorrectly?
 
msdn said:
WebException: The exception that is thrown when an error occurs while accessing the network through a pluggable protocol.
bad username/password isn't exceptional, it's just bad data. I would assume web exception is for bad protocols, or non-existent domains.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top