web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

How to assign Web Roles to a portal contact programmatically?

(0) ShareShare
ReportReport
Posted on by 40

Hi,

In my current ADX portals project, on click of SigIn link the page is redirected to an external authentication provider where the users get authenticated and redirects  back to the Portal SignIn page. Now in page load event the system checks for an external cookie in the response and creates a new portal user by calling UserManager.Create method.

After creating the portal user, the system determines a web role based on some conditions and assign the web role to the user. I tried using the OOB method UserManager.AddToRole but this is not supported in ASP.Net Identity Model. Can some one suggest how to assign a web role to a portal user programmatically using OrganizationService.Associate or any other approaches.

Thanks,

Manas

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi ManasK,

    This is a method of automatically assigning web roles to portal users using Workflows.

  • ManasK Profile Picture
    40 on at

    Does these workflows run synchronously and how would I know whether the workflow is succeeded?

    As of now I have coded this method and it works as expected

    private void AssignWebRole(ApplicationUser user, string webRole)
            {
                using (var xrmService = new OrganizationService("Xrm"))
                {
                    QueryExpression query = new QueryExpression
                    {
                        EntityName = "adx_webrole",
                        ColumnSet = new ColumnSet("adx_name"),
                        Criteria = new FilterExpression()
                        {
                            Conditions =
                            {
                                new ConditionExpression("adx_name", ConditionOperator.Equal, webRole),
                            }
                        }
                    };
                    var role = xrmService.RetrieveMultiple(query).Entities;
    
                    xrmService.Associate("contact",
                        new Guid(user.Id),
                        new Relationship("adx_webrole_contact"),
                        new EntityReferenceCollection() { new EntityReference("adx_webrole", role[0].Id) });
                }
            }


    I understand assigning web roles through workflow is a better approach, but my only worry is what if the workflow fails and how would I get the result in the UI and will the workflow work synchronously? 

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi ManasK,

    The Run this workflow in the background (recommended) setting determines whether the workflow is a real-time or background workflow. Real-time workflows run immediately (synchronously) and background workflows run asynchronously. The configuration options available depend on your choice for this setting. Background workflows allow for wait conditions that are not available for real-time workflows. As long as you do not use those wait conditions, later you can convert background workflows to real-time workflows and real-time workflows to background workflows.

    This article describes monitoring and management of processes, including background workflows, real-time workflows and actions. You can use this information to monitor successful and failed workflow jobs.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans