Problem: domainServiceContext.User.Identity.IsAuthenticated always returns false and therefore domainServiceContext.User.Identity.Name returns and empty string (“”)
Solution: Enable WindowsAuthentication and disable AnonymousAuthentication on IIS Express using the Web project’s properties page.
I have a Silverlight 5 application, that was created in Visual Studio 2010, using Windows authentication, but when I open the application in visual Studio 2013 a call to domainServiceContext.User.Identity.IsAuthenticated always returns false and therefore domainServiceContext.User.Identity.Name returns and empty string (“”)
Note: domainServiceContext is an instance of the DomainServiceContext class in the System.ServiceModel.DomainServices.Server dll and namespace.
In my particular case the problem was that on Visual Studio 2010 the application was running under the Visual Studio Development Server but in Visual Studio 2013 it was running on IIS Express, since the Visual Studio Development Server was replaced with IIS Express.
IIS Express by default, seems to have AnonymousAuthentication enabled and WindowsAuthentication disabled, as you can see on the <authentication> section of the IIS Express’ configuration file which is located in %USERPROFILE%\Documents\IISExpress\Config\applicationhost.config as shown below:
<anonymousAuthentication enabled=”true” userName=”" />
<basicAuthentication enabled=”false” />
<clientCertificateMappingAuthentication enabled=”false” />
<digestAuthentication enabled=”false” />
<add value=”Negotiate” />
<add value=”NTLM” />
The solution was to enable Windows Authentication and disable Anonymous Authentication, which you can do by changing the defaults settings in the applicationhost.config file, or better yet by changing these settings at the project level, by going to the web project hosting the Silverlight application’s properties page by clicking on the project name and press F4, as shown below:
Note: If you previously converted the application to Visual Studio 2013 and created a Virtual Directory by clicking the Create Virtual Directory button in the Properties dialog from the Web tab as shown below, and changed the settings as explained above:
You will get a dialog screen saying the settings will be change, if you try to convert the project again from Visual Studio 2010 to 2013 (from a backup for example) as shown here:
That’s because creating the Virtual Directory will create a location entry in the same applicationhost.config configuration file, specifying those values as shown here:
<windowsAuthentication enabled=”true” />
<anonymousAuthentication enabled=”false” />