如何从Angular中使用浏览器的URI启动一个通用的Windows应用程序,并将对象传递给自动登录



我们应该如何从一个带有浏览器URI的angular代码中启动一个UWP应用程序,并向它传递一些信息,如用户名、密码和其他信息。我们在angular应用中加密凭证,在UMP应用中解密。

我们应该如何使用浏览器的URI从angular代码中启动UWP应用程序,并将一些信息作为userid传递给它

对于这种情况,你可以参考Handle URI激活和注册你的应用程序的URI方案,当你启动特定的url时,你可以从应用程序的OnActivated方法获得路径和参数。

例如

<a href="testapp:login?userid=1234&password=7894">Launch</a>

AppOnActivated

public static Dictionary<string, string> ParseQueryString(Uri url)
{    
if (string.IsNullOrWhiteSpace(url.Query))
{
return new Dictionary<string, string>();
}

var dic = url.Query.Substring(1)

.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries)

.Select(param => param.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))

.GroupBy(part => part[0], part => part.Length > 1 ? part[1] : string.Empty)

.ToDictionary(group => group.Key, group => string.Join(",", group));
return dic;
}
protected override void OnActivated(IActivatedEventArgs e)
{
// set up frame
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
}
Type deepLinkPageType = typeof(MainPage);
if (e.Kind == ActivationKind.Protocol)
{
var protocolArgs = (ProtocolActivatedEventArgs)e;
var dict = ParseQueryString(protocolArgs.Uri);
switch (protocolArgs.Uri.AbsolutePath)
{
case "":
break;
case "login":
//navigate to login page with above dict parameter
break;

}
}
if (rootFrame.Content == null)
{
// Default navigation
rootFrame.Navigate(deepLinkPageType, e);
}
// Ensure the current window is active
Window.Current.Activate();
}

相关内容