2

I want to be able to get the default credentials from a within a windows service. However if I call

var credentials = CredentialCache.DefaultCredentials;

Or

var networkCredentials = CredentialCache.DefaultNetWorkCredentials;

The NetworkCredential returned (as an ICredential) the UserName and Domain etc are empty. I am running the windows service under a domain account.

If I create a simple console application then a valid credential is returned.

The reason I need this is to be able to set the credentials on a signalR HubConnection. The SignalR service is running in IIS with Windows Authentication enabled. The only way I can see to do this is to set the HubConnection.Credentials property. But as explained above I cannot get the credentials when I am running in a windows service.

Can anyone help?

rideintothesun
  • 1,628
  • 2
  • 12
  • 29
  • Credentials are stored per-user. Are you running the console application from the *same* user account that the service runs in? – Harry Johnston Feb 20 '15 at 05:17
  • Yes both are using the same account – rideintothesun Feb 21 '15 at 15:38
  • On the same computer? Also, I've just realized I'm not sure I read the question correctly: do you mean that the code that needs to establish the connection is running under IIS, or that it is trying to connect to an IIS server? (In the latter case I would expect it to work without setting any credentials, since you're using Windows Authentication.) – Harry Johnston Feb 21 '15 at 22:17
  • The situation is I have a windows service which needs to call a signalr service which runs in IIS. IIS has windows authentication enabled – rideintothesun Feb 22 '15 at 23:41
  • What happens if you don't set the `HubConnection.Credentials` property? – Harry Johnston Feb 23 '15 at 01:54

1 Answers1

0

I found this was not the issue after all and not being able to retrieve the credentials was a red herring (I found I could not retrieve them in the console either), when calling into the SignalR hub the identity is passed and the request authenticated by IIS.

But to conclude. This was my stupid mistake, nothing to do with the default credentials.

As a side note, the credentials are not available to retrieve on purpose see link

rideintothesun
  • 1,628
  • 2
  • 12
  • 29
  • 1
    I don't understand what is the actual solution. How did you pass the credentials to SignalR running in IIS, with Windows Authentication. Can you provide more details? – bdaniel7 Oct 29 '15 at 10:26
  • I didn't, it was a different issue. The path through the load balancers was blocking me. Once this was configured in the load balancer everything started working. – rideintothesun Nov 18 '15 at 15:08