When running a web app or windows service and making web requests to other sites, I specify the credentials this way:
var test = (HttpWebRequest)WebRequest.Create(uri);
test.Credentials = CredentialCache.DefaultNetworkCredentials;
This works until there has been an outage on the site for an extended period of time (several hours). Once the site is available and accessible, the following error is generated for each connection attempt until the windows service is restarted.
System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
What would be the best way to get around this? It's difficult to deal with because a small outage on a site can happen at any point, and I need to be able to log into the server and restart the application freely in order for regular business to resume.
edit: Actually, the exception that is usually repeated until I restart the service is usually, but not always:
The remote server returned an error: (401) Unauthorized
Sorry about that.