The GetCookie service takes as input the name of the cookie that we would like to retrieve from the user's computer. It must previously have been created for a meaningful result to be returned and it cannot have expired.
Cookies are small files which are stored on the user’s computer for a certain number of days. The users have the ability to view the cookies stored on their computer for the various sites they visit and view the data, so it is often encrypted. These can be useful when you want to save a variable and not have it wiped when the user’s IIS session ends on the session timeout or when closing the browser.
GetCookie Use Examples
Basic GetCookie Use
In this process we are retrieving a cookie named “UserId”. During an actual use case, you will know the name of the cookie you want to retrieve because either you or another developer has created it.
This service takes only one input, “Name”. This is the name of the cookie that we would like to retrieve. In this example, we are trying to retrieve a cookie named UserId.
We can see the value of the cookie named UserId in output logs.This output value can be used by any other services.
If the value saved in the “UserId” cookie was encrypted, it’s value would be a long encrypted string, which we could then feed into a Decrypt service to get the actual value.
Using GetCookie for the Remember Me Feature on Login
In this example, the user has previously logged in successfully with the “Remember Me” box checked. Here is what that looks like:
Here is what those cookies look like on a browser:
If we expand one, we can see the Name, Value, and ExpireInDays that we set in the service
The reason we wanted this to be saved in a cookie is because now when the user returns to our site in 2 weeks, the cookie will still be saved and can be auto filled into the UserId and Password text boxes when arriving on the login page.
When the page loads, we look for the cookie EPUser and EPPassword. If they are found, we set them on the page. This allows the user to sign in easily by clicking the “LOGIN” button without having the enter the information. Here is what that process canvas looks like:
These are the GetCookie services:
Here are the logs from those services:
Notice the returned value for the cookies matches the Content of the cookie when viewed through the browser. This is why we must encrypt our cookies, because the full string is viewable to the user as is.
If we wanted to go any further, we would decrypt the this result and fill in the text boxes with the values the user wanted to save. Now the user would not need to enter any credentials and could simply click “LOGIN”.
Retrieving a Cookie that has expired or Doesn’t Exist
If a cookie has never or no longer exists, the service will throw an exception.
When we want to check if a cookie was returned, we usually do the following check:
In an example of a userid or password, a blank cookie doesn’t make any sense, so this check makes sure we have received a meaningful result.