Asp.Net 4.0 - Custom Output Caching Provider (Design Patterns in Action)

Desing Patterns in Action

Today we will develop a custom output caching provider in asp.net 4.0. In .net framework 4.0 microsoft has emphasized on provider model for pluggable development. The provider model in .net 4.0 has been used and promoted extensively.

Developers can write their custom provider for logging, membership, caching, viewstate without affecting the existing application and plug that up with just configuration changes.

I will try to show this by writing custom file based output caching for asp.net 4.0 application. There may be scenario where memory based caching is expensive, so we can make use of provider model and write our own custom output caching.

Let's start-

1. Create a C# Library Project

2. Add reference to System.Web dll


Learning C# Design Patterns Series -Why Design Patterns

Design Patterns - The Best Practices

Few years back, design patterns for .net developers were less known though it is widely being used by java developers.

So as .net languages and developers got more matured over the time, people started looking for .net code optimization, performance, best practices, extensibility and maintainability of the code side.

First obvious question about making use of design patters is why? Why we should implement design patterns in our solutions/applications.

Well I will try to read and make notes of why and how of design patterns and share in this series. So let begin.

1. Why design patterns? What benefit I will get?

Productivity: Design pattern helps to build an architecture which can enhance the productivity.

Extensibility: When a software is released and becomes successful and widely accepted it is obvious that it will receive lots of request change and updates. So if while building the application proper design patterns is implented it will be easy to supply those updates and request. Most design patterns promote the idea of coding against interfaces and base classes, which makes it easier to change and enhance your application at a later stage.

Simplicity: Our solution architecture should be simple, well thought out, clean, crisp and easy to understand. This can be acheived by knowing the design pattern in advance.More...

Microsoft.Net Debugging and Tools (.Net Debugging Series)

Debugging is one of most common activity that every developer has to deal with in its day to day development life cycle. So It is very important that one should know the proper debugging technique and also could use the correct tools for debugging that particular issue.

But quite often it happens that developers are using wrong tools trying to investigate a particular problem. Sometimes developers are lucky to identify the exact place of code for the problem. And some times in spite of extensive code review still the problem is not caught because may be they are looking at wrong place or incorrect tool/no tool is used for debugging.

There are many powerful and free investigative tools which can dramatically reduce the troubleshooting time. These tools are very efficient and used by most of the professional developers. As fact we should know that a single tool can not address the every problem as each of these tools focus on a specific category. So knowing when and how to use each tool is very important for debugging .net applications.

Debugging Tools for Windows

URL: www.microsoft.com/whdc/devtools/debugging/default.mspx

Debugging Tools for Windows 32-bit Versions
Debugging Tools for Windows 64-bit Versions

There are three user mode debuggers available in the Debugging Tools for Windows package—NTSD, CDB, and WinDbg—and one kernel mode debugger (kd). Although these debuggers are three separate tools, it is important to understand that they all rely on the same core debugger engine. The most significant difference between the debuggers is that WinDbg has a graphical user interface (GUI) component, making it easier to work with when doing source level debugging. In contrast, NTSD and CDB are purely console-based debuggers. The snippets of debugger conversation that will be outlined in the book are all captured using NTSD.

After choosing the flavor of the debugger (32-bit or 64-bit), the installation process for Debugging Tools for Windows is straightforward and the default installation options are typically sufficient. The default installation path is

%programfiles%\Debugging Tools for Windows

here are several versions available for download. I have used version

Working and Debugging with .Net Framework 2.0

.Net 2.0 SDK Path: (%programfiles\Microsoft.net\SDK)


C# - Swapping values of two variables without using third variable



Lots of guys are asked and have delved into solving a very common question - How do you swap values of two variables without using third variable?

Well there are more than one ways, we could achieve it.

So first let's start from school days.

1. using 3rd variable:


class Program
        static void Main(string[] args)

        private static void SwappingUsingThirdVariable()
            int num1=7, num2=9, num3=0;
            Console.WriteLine("Before swapping: num1={0}, num2={1}", num1, num2);
            num3 = num1; num1 = num2; num2 = num3;
            Console.WriteLine("After swapping: num1={0}, num2={1}", num1, num2);



2. Witout using third variable and with help of plus/minus (+,-) operator: 


private static void SwappingUsingPlusMinusOperator()
            int num1 = 7, num2 = 9;
            Console.WriteLine("Before swapping: 

num1={0}, num2={1}", num1, num2);
            if (num1 > num2)
                num1 = num1 + num2;
                num2 = num1 - num2;
                num1 = num1 - num2;
                num2 = num2 + num1;
                num1 = num2 - num1;
                num2 = num2 - num1;
            Console.WriteLine("After swapping: 

num1={0}, num2={1}", num1, num2);



3. Witout using third variable and with help of mulitply/divide(*,/) operator:More...

ASP.Net - Uploading Multiple Files Like Gmail / Orkut

C#/Asp.Net - Uploading multiple files like Gmail/Orkut

There are several ways of supporting multiple file upload in asp.net based on the requirements. Below are few ways that we can do coding to support multiple file uploads in asp.net:

1. If we fix number of files to be uploaded, we can place that many FileUpload control while designing the page.

2. But if we dont know how many files user will select like Gmail/Orkut, we can achieve this with JavaScript by creating controls on fly on the page and iterating through the HttpFileCollection class in asp.net/c#.

So lets see the complete code. Screenshots of the code:


T-SQL Password Encryption / Decryption Using Password Phrase

T-SQL - Password Encryption/Decryption

Here is a sample code which will show how to encrypt/decrypt password using password phrase in T-SQL:

We will hard code password phrase and and original password then we will encrypt the password and store it in a variable.

Declare variables:


@passPhrase NVARCHAR(50),
@encryptedPass VARBINARY(MAX),
@decryptedPass NVARCHAR(50);




Posts By Month