ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Core Namespace / ArcGISPortalManager Class / SetActivePortal Method
The portal to be set active
Example

In This Topic
    SetActivePortal Method
    In This Topic
    Sets the currently active portal. This will result in the ArcGIS.Desktop.Core.Events.ActivePortalChangedEvent being published. This method should be called from within a QueuedTask or System.Threading.Task unless the caller is within ArcGIS.Desktop.Framework.Contracts.ConfigurationManager.OnApplicationInitializing in which case the main thread should be used.
    Syntax
    public bool SetActivePortal( 
       ArcGISPortal portalObj
    )
    Public Function SetActivePortal( _
       ByVal portalObj As ArcGISPortal _
    ) As Boolean

    Parameters

    portalObj
    The portal to be set active

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called on a valid ArcGISPortal object. This object may have been edited or removed.
    Thrown when a method is called on the wrong Pro thread
    Example
    ArcGISPortalManager: Get a portal and Sign In, Set it Active
    //Find the portal to sign in with using its Uri...
    var portal = ArcGISPortalManager.Current.GetPortal(new Uri(uri, UriKind.Absolute));
    if (!portal.IsSignedOn())
    {
      //Calling "SignIn" will trigger the OAuth popup if your credentials are
      //not cached (eg from a previous sign in in the session)
      if (portal.SignIn().success)
      {
        //Set this portal as my active portal
        ArcGISPortalManager.Current.SetActivePortal(portal);
      }
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also