How to enable sessions in Web API

Web API does not support native HTTP sessions. And it’s the nature of Web API, but there might be times you need HTTP sessions which resembles your bad design. Because a service framework should not support HTTP sessions as it should be a stateless element. So why do we need sessions in Web API ? … Continue reading How to enable sessions in Web API

Advertisements

AES Cryptography

Contains the code for AES encryption and decryption in C#. 1: public byte [] EncryptText(string plainData) 2: { 3: RijndaelManaged rij = new RijndaelManaged(); 4: 5: rij.GenerateKey(); 6: _key = rij.Key; 7:  8: rij.GenerateIV(); 9: _intializationVector = rij.IV; 10:  11: ICryptoTransform encryptor = rij.CreateEncryptor(_key, _intializationVector); 12:  13: using (MemoryStream msEncrypt = new MemoryStream()) 14: { … Continue reading AES Cryptography

checked and unchecked keywords in C#

This post explains about checked and unchecked keywords in C#. In arithmetic calculations when constants are involved compiler detects the overflows in the data types. For example look at the following code. 1: // int range is from -2,147,483,648 to 2,147,483,647 2: int i = 2147483647 + 10; The above will generate a compile time … Continue reading checked and unchecked keywords in C#

Detecting the Windows Phone Theme Background Color

We often need to detect the WP background theme color to switch the color schemes of our apps. This is very useful when we utilize the application bar and have some metro icons in our app. In built WP apps have this feature and switch between different icons. For example when you use the Messaging … Continue reading Detecting the Windows Phone Theme Background Color

Singleton Pattern

Singleton pattern is a simple design pattern in software practice and sometimes considered as an anti-pattern due its tight coupling nature. A very simple non thread safe implementation of the Singleton pattern would be like this. Singleton non thread safe class Singleton {   privatestatic Singleton _instance;   private Singleton()   {     Console.WriteLine("Singleton instantiated"); … Continue reading Singleton Pattern