Encryption Using MachineKey in .NET Framework

In .NET Framework 4.6, 4.5, 4 you can now encrypt your text using MachineKey in your web.config file. This encryption depend on System.Web.dll so you need to add reference of it before. NOTES:

  • If you have multiple web front end server, then the machine key should be same on all WFEs.
  • You may need to use Base64 encoding to convert encrypted or decrypted bytes to text so you can send it over HTTP,email or any textual transfer system.

Encrypt Method

 private static string Encrypt(string plainText)
     byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

     byte[] encryptedBytes = MachineKey.Protect(plainTextBytes);

     string encryptedText = Convert.ToBase64String(encryptedBytes);

     return encryptedText;

Decrypt Method

 private static string Decrypt(string encryptedText)
     byte[] encryptedBytes = Convert.FromBase64String(encryptedText);

     byte[] plainTextBytes = MachineKey.Unprotect(encryptedBytes);

     string plainText = Encoding.UTF8.GetString(plainTextBytes);

     return plainText;

PlatformNotSupportException When Using VS 2012 With SharePoint 2013

While I writing a small console to insert items in SharePoint 2013 task list, I got the follwoing error:

Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable.

An her the screen shot of the exception:



Right click on the project in Solution Explorer and click on Properties


Then go to Build tab and do the following:

  • Platform target >> Any CPU
  • Clear the check box on “Prefer 32-bit


“Open with Explorer” is very slow in SharePoint 2010

In SharePoint 2010 , when you try to open a document library with windows explorer you may notice that it took too much time and very slow to open.


Actually, I solved this by clear the check box “Automatically detect settings” in LAN Settings of internet option.



Using HTTPS with basicHttpBinding in WCF Gateway

WCF can work as gateway and in this case you need to configure the service endpoint and client endpoint.

In some cases your client endpoint is HTTPS  and you are using basicHttpBinding. basicHttpBinding suppose you are not using HTTPS.

You need to define your own binding configuration with security mode set to Transport


    <endpoint name="clientEndPoint" 
              contract="*" />

        <binding name="MyBasicHttpBinding">
           <security mode="Transport">

Changing the Duration column unit in Microsoft Project Professional

If you need to change the unit of Duration column from Days to Hours or vise-verse follow the below steps:


  • Open Microsoft Project
  • Go to Options


  • Go to Schedule >> Duration is entered in :


Using New Code Nuggets in ASP.NET4

We will talk about new feature in ASP.NET 4.

Suppose you have the following code-behind property and you need to use it in ASPX page.



In ASPX page you can render the property MyContent like below:



And this will render the below output:

This is an XSS (cross-site script injection) and the developer should be aware of this, so he should do an HTMLEncode


Because of many developer may forget to do this, ASP.NET introduced the below code nugget

Now, the result will be;