Hi Guys,
I am using this code to automatically login into ArcGIS portal, it is working perfectly in 2.5.
We have setup new environment to test existing addin with 2.6, repackage with 2.6 nugget and deployed.
The code snippet I am currently using is -
private void ForceLoginToDefinedPortal()
{
var portals = ArcGISPortalManager.Current.GetPortals();
var resultPortal = portals.FirstOrDefault(p => p.PortalUri.Host.Equals(this.Config.DefaultPortal, StringComparison.OrdinalIgnoreCase));
this.ModuleLogManager.LogInfo($"Got registered portal {resultPortal != null}");
try
{
if (resultPortal != null)
{
this.ModuleLogManager.LogInfo($"switch active portal to {this.Config.DefaultPortal}");
ArcGISPortalManager.Current.SetActivePortal(resultPortal);
this.ModuleLogManager.LogInfo($"Start sign in to active portal to {this.Config.DefaultPortal}");
resultPortal.SignIn();
this.ModuleLogManager.LogInfo($"Sign in success to active portal to {this.Config.DefaultPortal}");
}
}
catch (Exception loginExcep)
{
string err = $"login issue {loginExcep.Message}{Environment.NewLine}{loginExcep.StackTrace}";
this.ModuleLogManager.LogError(err);
}
}
In 2.6 I got exception and below is the detail log
INFO ||2020-11-12 05:05:47||Username:ProAddinTestUser||Current Login User ProAddinTestUser
INFO ||2020-11-12 05:05:47||Username:ProAddinTestUser||Config App initialized success
INFO ||2020-11-12 05:05:47||Username:ProAddinTestUser||Got registered portal True
INFO ||2020-11-12 05:05:47||Username:ProAddinTestUser||switch active portal to dummyportal.com.au
INFO ||2020-11-12 05:05:47||Username:ProAddinTestUser||Start sign in to active portal to dummyportal.com.au
ERROR ||2020-11-12 05:05:47||Username:ProAddinTestUser||login issue Error HRESULT E_FAIL has been returned from a call to a COM component.
at ArcGIS.Desktop.Internal.Framework.IAGOSignOnService.GetToken(String portalURL)
at ArcGIS.Desktop.Core.ArcGISPortal.SignIn()
at ProConfigurationManager.ForceLoginToDefinedPortal() in
I didn't get any login prompt and got that exception only, the designated portal is using IWA auth.
Any Idea?
Solved! Go to Solution.
Hi Guys,
Manage to solve it today.
The issue is where I called this method, need to call that method only when application is ready.
In ApplicationReady event, previously I called it at Applicationinitializing event.
It seems, application loading sequence might change in 2.6.
Do you have a reverse proxy in between?
(Ex. When you go to https://mahinename/portalwebadaptor/home does it redirect you to another page for login?
I faced a similar issue and we had to disable the reverse proxy to achieve this.
Thank @YatharthSah ,
Is does look like that and it is a good point.
I wish to update pro.exe.config file with fiddler proxy and test as well but IT does not allow me to.
I will check with them how the internet traffic from that image is going through.
Best Regards,
Than
Hi Guys,
Manage to solve it today.
The issue is where I called this method, need to call that method only when application is ready.
In ApplicationReady event, previously I called it at Applicationinitializing event.
It seems, application loading sequence might change in 2.6.
Thanks for this Than. This is a bug. 2.7 is almost final and so we cannot get the fix in for 2.7. We will fix this in 2.8
Thank for your reply @CharlesMacleod
Additionally I noticed some custom property in the configurationmanager class or from module seems to change.
I can't pin point it yet. The object is retained but it does not execute correctly.
Example : I initialized the log4net log manager object in initialize method, but in subsequent class (in startup page viewmodel, dockpane viewmodel) the logging mechanism seem to corrupt.
I have to initialized those object in OnApplicationReady event as well.
I've just tried it out with the latest 2.8 and we still have the problem!
I had the same issue and had to move my code to OnApplictionReady from OnApplicationInitilize. It worked for years and then 2.6 came out and I started getting the COM error. I wonder what has changed in the start up sequence.
protected override void OnApplicationReady()
{
// get the login username from Portal
var portal = ArcGISPortalManager.Current.GetActivePortal();
//Module1.UserName = portal.GetSignOnUsername();
if (portal != null && portal.SignIn().success)
{
Module1.UserName = portal.GetSignOnUsername();
}
}
How do you handle when the token has expired and you have to input the password?