I have a website deployed on a Windows 2008 R2 server on IIS 7.5 that is accessed remotely. I am using Windows Integrated Authentication and reading a user's displayname ("Bloggs, Joe") which is displayed on the page.
This was working fine until Friday, when all of a sudden I am getting the following error:
The Workstation service has not been started.
[COMException (0x8007085a): The Workstation service has not been started. ] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +387793
Removing the following line of code stops the error from being thrown.
DirectoryEntry directory_entry = new DirectoryEntry("WinNT://" + Environment.UserDomainName + "/" + Environment.UserName);
ViewBag.Username = directory_entry.Properties["fullName"].Value.ToString();
Interestingly, this error only occurs when I access the website remotely. Accessing it from the server works without issue.
The 'Workstartion' service is running. I have restarted it and rebooted the server to no effect. I have restarted the website in IIS and recycled the AppPool.
I have searched the bowels of the internet and cannot find a solution to this problem. Can anyone offer insight?
I had this issue pop up as well - I was just in the process of implementing (reusing) some code that did a similar thing. It turns out that in my case the error message was a little bit of a red herring - it was complaining that it couldn't connect. That was because of impersonation and the double-hop issues associated with that. Once I wrapped the DirectoryEntry in a using block and fell back to the application pool account, everything worked just fine:
var s = "WinNT://" + Environment.UserDomainName + "/" + Environment.UserName;
using (System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero))
using (var de = new System.DirectoryServices.DirectoryEntry(s))
{
ViewBag.Username = de.Properties["fullName"].Value.ToString();
}