Thursday, August 4, 2011

Application Pool

Application Pool
Application pool is actually related with IIS where your web application resides. Every web application need some memory and application pool is for this. Application pool maintain connections, worker processes etc. Many application can share one application pool but it is good to separate pool for every application.
OR
Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries. Application pools used to isolate our web application for better security, reliability, and availability and performance and keep running with out impacting each other . The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected.
One Application Pool can have multiple worker process Also.

Main Point to Remember:
1. Isolation of Different Web Application
2. Individual worker process for different web application
3. More reliably web application
4. Better Performance


What is a Site Collection Administrator?
Site Collection definition: A set of Web sites on a virtual server that have the same owner and share administration settings. Each site collection contains a top-level Web site and can contain one or more subsites. The only role that has permission over the entire collection of sites is the Site Collection Administrator.

Site Collection Vs Application Pool

n every web application in Sharepoint has one default site collection and application pool. Site collection means a site which can contain many sites under it. One web application can have many site collections. Application pool is actually related with IIS where your web application resides. Every web application need some memory and application pool is for this. Application pool maintain connections, worker processes etc. Many application can share one application pool but it is good to separate pool for every application.

Worker Processes (IIS 6.0)

Worker Processes (IIS 6.0)
A worker process is user-mode code whose role is to process requests, such as processing requests to return a static page, invoking an ISAPI extension or filter, or running a Common Gateway Interface (CGI) handler.
In both application isolation modes, the worker process is controlled by the WWW service. However, in worker process isolation mode, a worker process runs as an executable file named W3wp.exe, and in IIS 5.0 isolation mode, a worker process is hosted by Inetinfo.exe. Figure 2.2, which depicts the architecture for IIS 5.0 isolation mode, uses a dashed line to suggest the relationship between the worker process and the WWW service.
Worker processes use HTTP.sys to receive requests and to send responses by using HTTP. Worker processes also run application code, such as ASP.NET applications and XML Web services. You can configure IIS to run multiple worker processes that serve different application pools concurrently. This design separates applications by process boundaries and helps achieve maximum Web server reliability.
By default, worker processes in worker process isolation mode run under the Network Service account, which has the strongest security (least access) compatible with the functionality that is required. For more information about Network Service accounts, including Windows Server 2003 built-in security accounts, see Running IIS 6.0 as an Application Server, and IIS and Built-in Accounts.

How to Get an Enum from a Number

Here’s the function that will be doing all the work:
public T NumToEnum<T>(int number)
{
return (T)Enum.ToObject(typeof(T), number);
}

This is a generic function that can convert a number to any type of enum. Let’s see some sample code that makes use of this function. First, let’s create some enums.
public enum DaysOfWeek{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
public enum MonthsInYear{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
}

Now, let’s see some code that uses NumToEnum.
int day = 3;
int month
= 10;
DaysOfWeek d = NumToEnum<DaysOfWeek>(day);
//d is now DaysOfWeek.Thursday
MonthsInYear m = NumToEnum<MonthsInYear>(month);
//m is now MonthsInYear.November

Different Ways of using the C# Null Coalescing Operator


The C# Null-Coalescing operator or the ?? operator is a binary operator that returns the left-hand operand if it is not null; otherwise it returns the right operand. It can be used with both nullable and reference types.
Here’s a simple example of using the Null-Coalescing operator
int? i = null;
int j = i ?? 2;
// here the resultant value of j is 2
Here are some additional ways of using the Null-Coalescing operator in your code.

Method 1
string address = homeAddress1 ?? homeAddress2 ?? officeAddress
?? "No Address";
returns the first non-null value in this long expression. This expression returns “No Address” if homeAddress1, homeAddress2 and officeAddress are Null.


Method 2
While converting a Nullable Type to Non-Nullable type, we do an explicit cast to avoid assigning null values to a non-nullable type, as shown below:
int? a = NullType(); // returns nullable int
int b = (int)a;
instead you can avoid the explicit cast using a null-coalescing operator and write:
int? a = NullType();
int b = a ?? 0;

Method 3
private IList person;
public IList PersonList
{
   get
   {
       return person ?? (person = new List());
   }
}
Typical usage of the null-coalescing operator in a lazy instantiated private variable.


Method 4

string conn = Connection["TestMachineStr1"]
           ?? AppConnection["ProdMachineStr2"]
           ?? DefaultConnection["DefaultConn"];
Accessing NameValueCollections and choosing the first non-null value.

Note: The Null-Coalescing operator is useful but may sometimes be an overkill, especially when developers use it to flaunt their coding skills. I sometimes choose ‘understandable code’ over ‘terse code’, focusing on the intent.