Exemplo n.º 1
0
            public NetworkCredential GetCredential(Uri uri, string authType)
            {
                if (authType != "basic")
                {
                    return(null);
                }
                var credential = _cache.GetCredential(uri, authType);

                if (credential == null)
                {
                    using (var prompt = new UserCredentialsDialog
                    {
                        Target = new SDataUri(uri)
                        {
                            Path = null, Query = null
                        }.ToString(),
                        User = Settings.Default.UserName
                    })
                    {
                        if (prompt.ShowDialog() == DialogResult.Cancel)
                        {
                            throw new OperationCanceledException();
                        }
                        credential = new NetworkCredential(prompt.User, prompt.Password);
                        _cache.Add(uri, authType, credential);
                        Settings.Default.UserName = prompt.User;
                    }
                }
                return(credential);
            }
Exemplo n.º 2
0
 public NetworkCredential GetCredential(Uri uri, string authType)
 {
     if (authType != "basic")
     {
         return null;
     }
     var credential = _cache.GetCredential(uri, authType);
     if (credential == null)
     {
         using (var prompt = new UserCredentialsDialog
             {
                 Target = new SDataUri(uri) {Path = null, Query = null}.ToString(),
                 User = Settings.Default.UserName
             })
         {
             if (prompt.ShowDialog() == DialogResult.Cancel)
             {
                 throw new OperationCanceledException();
             }
             credential = new NetworkCredential(prompt.User, prompt.Password);
             _cache.Add(uri, authType, credential);
             Settings.Default.UserName = prompt.User;
         }
     }
     return credential;
 }