【问题标题】:Authentication user to web application from desktop application从桌面应用程序向 Web 应用程序验证用户
【发布时间】:2017-03-06 09:46:08
【问题描述】:

我是一个新手程序员。我需要编写桌面应用程序,用户输入用户名和密码。单击按钮后调用方法 Start 类 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;
         }
      }
   }
}

【问题讨论】:

  • 请说明您的意图。您是否尝试将用户凭据转发到 Chrome 浏览器?
  • 是的。我尝试将用户凭据转发到 Chrome 浏览器以在 Web 应用程序中对他进行身份验证。
  • 为什么需要以其他用户身份启动 Chrome?

标签: c# asp.net visual-studio google-chrome process.start


【解决方案1】:

我认为你的方法行不通。至少不像你想象的那么简单。您可以通过使用显式凭据启动 Internet Explorer 以针对 IIS 中托管的应用程序进行身份验证来使其正常工作,因为它们可能被配置为使用域帐户进行身份验证。此方案本质上是针对 Intranet Web 应用程序的。对于 Crome,情况就完全不同了。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多