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.
Click on “Add Rule” and select “Blank Rule” from the menu.
Your final rule should look like below.
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!
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.