private void InitializeToken() { _error = string.Empty; var token = HostingEnvironment.CreateUserToken(_userName, _password, out _error); _impersonateTokenRef = new ImpersonateTokenRef(token); if (_impersonateTokenRef.Handle == IntPtr.Zero) { if (_error.Length > 0) { throw new ConfigurationErrorsException(string.Format("Invalid_credentials_2", _error), ElementInformation.Properties["userName"].Source, ElementInformation.Properties["userName"].LineNumber); } throw new ConfigurationErrorsException("Invalid_credentials", base.ElementInformation.Properties["userName"].Source, base.ElementInformation.Properties["userName"].LineNumber); } }