C# 从桌面应用程序到web应用程序的身份验证用户
我是一个新手程序员。我需要写桌面应用程序,用户输入用户名和密码。单击按钮后,调用方法启动类进程。很遗憾,出现在错误消息System.ComponentModel.Win32中。异常情况下,用户名或密码不正确 我的代码:C# 从桌面应用程序到web应用程序的身份验证用户,c#,asp.net,visual-studio,google-chrome,process.start,C#,Asp.net,Visual Studio,Google Chrome,Process.start,我是一个新手程序员。我需要写桌面应用程序,用户输入用户名和密码。单击按钮后,调用方法启动类进程。很遗憾,出现在错误消息System.ComponentModel.Win32中。异常情况下,用户名或密码不正确 我的代码: //Download data String user = this.textBoxUser.Text; String pass = this.textBoxPassword.Text; //Password SecureString secret = SecureStrin
//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应用程序的。对于克罗姆来说,这是一个完全不同的故事 你的方法的优点并不明显。登录到Windows的用户的凭据应用于身份验证。根据您的想法,这听起来更像是其他人为我登录Windows,我使用自己的凭据运行web应用,但仍然使用其他人的凭据使用其余的Windows应用 下面的文章应该让您了解到,这将取决于基础架构支持和特定的登录过程,而不仅仅是转发显式凭据以使其与对您的域一无所知的外部web应用程序一起工作:
请澄清您的意图。您正在尝试将用户凭据转发到Chrome浏览器吗?是。我尝试将用户凭据转发到Chrome浏览器中,以便在web应用程序中对其进行身份验证。为什么需要以其他用户身份启动Chrome?