Can anyone tell me how to get the signed-in username in ArcGIS Pro using C#/.NET SDK?
Solved! Go to Solution.
You can get the signed in user name for the current active portal, but only when the user signed in.
QueuedTask.Run(() => {
var portal = ArcGISPortalManager.Current.GetActivePortal();
if (portal != null) {
// make sure is signed in
var IsSignedOn = portal.IsSignedOn();
if (!IsSignedOn) portal.SignIn();
var signOnUserName = portal.GetSignOnUsername();
// ...
}
});
You can get the signed in user name for the current active portal, but only when the user signed in.
QueuedTask.Run(() => {
var portal = ArcGISPortalManager.Current.GetActivePortal();
if (portal != null) {
// make sure is signed in
var IsSignedOn = portal.IsSignedOn();
if (!IsSignedOn) portal.SignIn();
var signOnUserName = portal.GetSignOnUsername();
// ...
}
});
Side Question: Can you run QueuedTask.Run in the Module1.cs? I ask because I received advice to have my business logic in the Module.cs to stay organized.
QueuedTask.Run(() =>
You can call QueuedTask.Run anywhere. Putting business logic into the Module class makes sense if you need access to your logic from various tools and buttons from within your add-in. Also note that you can access your Module class (which is a singleton) from any other add-in or managed configuration through FrameworkApplication.FindModule("MyAddIn_Module").
In your business logic make sure that you don't 'nest' calls to QueuedTask.Run, meaning that you should not call a function that calls QueuedTask.Run from within the context of another QueuedTask.Run action.
If you write re-usable functionality that is calling Pro API methods that require to run from within the context of QueuedTask.Run make sure to put the following comment in your summary description of your method:
This method must be called on the MCT.
The Pro API is using the same pattern for methods that need to run from the MCT.