MS CRM 2011: Customer Portal Contact Sign Up

Building off my previous post where I converted the authentication to what was used with the eService portal available for 4.0 http://wp.me/p1iFyd-52.  I am now making the customer sign up a little less cumbersome and more like the original.

First what we need to do is go back into our customer Portal.  If you have not created the newuser sign up page  you will need to do that and add the new user control from the tool box.

We are going to create a workflow that will send an email to the email on record for the contact with a link to this page and pass an id to it that we can then associate with the user that is created.  In the code behind of the Newuser page you will need this code.

public partial class Newuser : System.Web.UI.Page
    {
        private Guid _contactId;
        private string plainText;
        protected override void OnLoad(EventArgs e)
        {
            plainText = Request.QueryString["id"];
            _contactId = new Guid(plainText);
            CreateUserWizard1.CreatedUser += new EventHandler(CreateUserWizard1_CreatedUser);
        }
        private void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            ProfileCommon p = (ProfileCommon)ProfileCommon.GetUserProfile(CreateUserWizard1.UserName);
            p.ContactId = _contactId;
            p.Save();
            //associate the username with the contact record inside CRM
            var xrm = new XrmServiceContext("Xrm");
            var contact = xrm.ContactSet.Where(c => c.ContactId == _contactId).Single();
            contact.Adx_username = CreateUserWizard1.UserName;
            xrm.UpdateObject(contact);
            xrm.SaveChanges();
            //redirect to login page
            Response.Redirect("~/pages/login.aspx");
        }
    }

To access the AspNetSqlProfileProvider we need to create a class and we also need to add the property for the contactid that will associated our user.

using System;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
namespace Site.Pages
{
    public class ProfileCommon : ProfileBase
    {
        public static ProfileCommon GetUserProfile(string username)
        {
            return Create(username) as ProfileCommon;
        }
        public static ProfileCommon GetUserProfile()
        {
            return Create(Membership.GetUser().UserName) as ProfileCommon;
        }
        public virtual Guid ContactId
        {
            get
            {
                return ((Guid)(this.GetPropertyValue("ContactId")));
            }
            set
            {
                this.SetPropertyValue("ContactId", value);
            }
        }
    }
}

One last piece needs to be added to the web.config to tie this all together.

<profile inherits=”Site.Pages.ProfileCommon”>
<providers>
<clear />
<add name=”AspNetSqlProfileProvider” type=”System.Web.Profile.SqlProfileProvider” connectionStringName=”LocalSqlServer”/>
</providers>
</profile>
Notice that I inherit my class. By doing this we are letting the AspNetSqlProfileProvider know that we have added a new property and it will pull that into the Profile table.

At this point we have used a workflow to send the invitation email to the contact but we have not set up the permissions inside of CRM.  That is the last piece and until those permissions have been set up the contact will not actually have permission to see anything inside of crm.

About dorothyjarry

Super Dots
This entry was posted in CRM, Customer Portal. Bookmark the permalink.

2 Responses to MS CRM 2011: Customer Portal Contact Sign Up

  1. Mike says:

    Like the idea of this, however I get an error at the line _contactId = new Guid(plainText); saying it cannot be null. Also, I don’t get the secret question or answer boxes. Any ideas?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s