{Knowhow} Redirect User’s to an intermediate disclaimer page while logging in Dynamics CRM On-Premise

Recently my friend called me up and asked for a requirement where their client wanted to show a sign up page the first time a user logs in. Once the user signs in, from the next time onwards they would be able to login directly into CRM.

So I thought, why not a give it a try. I conceived of something like this.

  • Create a page for sign up. The page can be in the same root of Dynamics CRM or can be hosted under a different website altogether.
  • On load of the sign-up page, a check would be performed to determine if the user has already signed up. If not the sign up material would be shown to the user.

In case the user has not signed up

    • The user would signup
    • A cookie would be created and the user would be redirected to the CRM Application

If the user has already signed up

    • A cookie would be created again and the user would be redirected to the CRM Application.

 

The final step is to set up rewrite rules to redirect the user to the signup page or not based on the cookie value as described in the earlier step

 

Seems bit complicated? Don’t worry, I will go through each code of this in detail. So let’s first check for the rewrite rule.

Go to IIS –> Microsoft Dynamics Website –> Url rewrite. In case you do not find the rewrite module, you would need to install the re-write module.

image_thumb1

 

Click on “Add Rule” and select “Blank Rule” from the menu.

image_thumb3

 

Your final rule should look like below.

image

Rule Name – I named it CookieBasedRule. You can name it as you like.

 

In the Match URL section, you need to specify the source url for which the rewrite would happen. I have put it as (.*) to allow any requests coming to my Dynamics CRM site.

Now comes the main area, the conditions.

The first condition I have put {HTTP_HOST} should match org1.contoso.com. Off course in your case it would be different. So replace that with your host name.

The second condition is where I have put the cookie condition. The second condition basically checks for any cookies with name = “foo2” and value=”foo”. If it is not there the user is redirected to redirector.htm which is my signup page here. Please provide some unique name to the cookie here.

In the redirector.htm page once, the user performs the necessary action, I create a cookie like the one below.

$.cookie("foo2", "foo", { expires: 30 }); // You need to include jquery cookie plugin to execute $.cookie

I have created a cookie and then I would redirect the user back to CRM. This time when the rewrite url rule checks it would find the cookie and allow the user to the CRM application.

 

Great isn’t it? And now you may think that the user could go ahead and delete the cookies or the cookie may expire after 30 days. In that case the rule would redirect the use to the sign up page again. So in the on-load of the signup page you would need to determine if the user has already signed up and if he has just, re-create the cookie and redirect the user to the CRM url again to access the CRM application.

Hope this helps!

Advertisements

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

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

%d bloggers like this: