繁体   English   中英

从桌面应用程序到Web应用程序的身份验证用户

[英]Authentication user to web application from desktop application

我是新手程序员。 我需要编写桌面应用程序,用户在其中输入用户名和密码。 单击按钮后,调用方法Start class Process。 不幸的是,出现一条错误消息System.ComponentModel.Win32Exception,用户名或密码不正确。

我的代码:

//Download data
String user = this.textBoxUser.Text;
String pass = this.textBoxPassword.Text;

//Password
 SecureString secret = SecureStringConverter.ConvertToSecureString(pass);            
//Webbrowser
string file = "chrome.exe";
string domain = @"http://localhost:62074/";
//Process start
Process proc = new Process();

Microsoft.Win32.RegistryKey subKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command");
String DefaultBrowser = subKey.GetValue(null).ToString();

if (DefaultBrowser != null)
{
   int startIndex = DefaultBrowser.IndexOf("\"") + 1;
   int endIndex = DefaultBrowser.IndexOf("\"", startIndex);
   string RegDefaultBrowserPath = DefaultBrowser.Substring(startIndex, endIndex - startIndex);

   proc.StartInfo.FileName = RegDefaultBrowserPath;
   proc.StartInfo.Arguments = domain;
   proc.StartInfo.UseShellExecute = false;
   proc.StartInfo.LoadUserProfile = false;
   proc.StartInfo.UserName = user;
   proc.StartInfo.Password = secret;
   proc.Start();
}

而这种将字符串转换为SecureString的方法

public static class SecureStringConverter
{
   public static SecureString ConvertToSecureString(string password)
   {
      if (password == null)
         throw new ArgumentNullException("password");

      unsafe
      {
         fixed (char* passwordChars = password)
         {
            var securePassword = new SecureString(passwordChars, password.Length);
            securePassword.MakeReadOnly();
            return securePassword;
         }
      }
   }
}

我认为您的方法无效。 至少不像您期望的那样简单。 您可以通过使用显式凭据启动Internet Explorer来对IIS中托管的应用程序进行身份验证来使其工作,因为它们可能被配置为使用域帐户进行身份验证。 这种情况实质上是针对Intranet Web应用程序的。 对于Crome,这是一个完全不同的故事。

您的方法的优点完全不明显。 预期将使用登录到Windows的用户凭据进行身份验证。 按照您的想法,听起来更像是其他人为我登录Windows,我使用自己的凭据来运行Web应用程序,但仍然使用具有其他凭据的其余Windows应用程序。

以下文章应该使您了解,它将取决于基础结构支持和特定的登录过程,而不仅仅是像转发显式凭据以使其与对您的域名一无所知的外部Web应用程序一样简单:

https://support.google.com/a/answer/60224?hl=en

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM