Sunday, November 8, 2009

Installing IIS 7.0 on Windows Server 2008

Let me explain my experience on installing IIS 7.0 on windows server 2008. I had a tough time to find a way to install IIS 7.0 on windows server 2008. I thought that it would be same as installing IIS 6.0 on windows server 2003 by going to "control panel" -> "Add or Remove Programs" -> "Add/Remove Windows Components" and install IIS. But I couldn't find this in windows server 2008. After doing a long research I found a link which helped me.

I followed the below steps to install IIS 7.0 on windows server 2008.
  1. Go to "Start" -> "Administrative tools" -> "Service Manager".
  2. Right click the node "Roles" in the "Service Manager" window and click on "Add Roles".
  3. Follow the wizard.
  4. Select web server(IIS) in 2nd step of the wizard.
  5. You might get the following popup immediately. If you get this please click "Add Required Role Services".
  6. You follow the wizard until you get the below step.
  7. Follow the wizard until the final step.
  8. That's it. You are done with installing IIS 7.0 on windows server 2008.
  9. If you face any problems please follow the below link. It has detailed step by step guidelines to install the IIS 7.0 on windows server 2008. http://learn.iis.net/page.aspx/29/installing-iis-70-on-windows-server-2008/

kick it on DotNetKicks.com
Shout it

Thursday, November 5, 2009

C# 4.0 new features: Named and Optional arguments

Microsoft has introduced few new features in C# 4.0. I would like to discuss the below listed new features in this post.

1. Optional arguments
2. Named arguments

Optional arguments: This feature allows you to omit arguments when calling methods. This is done by defining a method with assigning default values to parameters. For better understanding, let's take a look at the below example.

We define a method called "SomeMethod" by proving default values to two of its parameters as shown.

public void SomeMethod(int a, int b = 50, int c = 100);

Now this method can be called in different ways as shown below.

SomeMethod(10, 30, 50); // This is a normal call as 3 arguments were passed

SomeMethod(10, 30); // This call is omitting parameter "c". This call is equalant to SomeMethod(10, 30, 100)

SomeMethod(10); // This call is omitting both "b" and "c". This call is equalant to SomeMethod(10, 50, 100)

As you see, we can omit any number of consecutive parameters from right to left. In the above examples we omitted parameter "c" alone and parameters "b" and "c" together. Do you see a way to omit the parameter "b" in the above example? If you call the method "SomeMethod" by passing one argument as shown below, the compiler assumes that the argument passed was for the first parameter i.e, "a". So we need a way to tell the compiler that this argument was passed to a particular parameter, in this case it is "b". This requirement was fulfilled by c# 4.0's another new feature called "Named Arguments". Let's take a closer look at this feature.

Named Arguments: This feature allows you to pass the arguments by the corresponding parameter names.

For example you can pass the arguments by name as shown below.
SomeMethod(a:10, b:30, c:50);

By this feature, we don't need to pass the arguments in the order of parameters defined in the method. We can rewrite the above method call as shown below.
SomeMethod(c:50, b:30, a:10);

And you can solve the above discussed problem (omitting the middle parameter "b") as shown below.

SomeMethod(a:10, c:50); // This call Omits the parameter "b".

Optional and Named arguments features can also be applied to constructors. This feature is mainly useful where you have methods that have many number of parameters. Because it is very difficult to call a method by passing the parameters in same order as the method was defined. There are many possibilities to make mistakes in the order. So, having named parameters and the ability to pass parameters in any order by explicitly referring the parameter names will make our life easier.

kick it on DotNetKicks.com
Shout it