Tuesday, February 7, 2012

Interview questions ASP.Net 4.0

Today, I'm posting some question for Asp.net Framework 4.

Q. What is new with ASP.Net 4 WebForms ?

Ans. Some of the Features are:

. Ability to Set Metatags.
. More control over view state.
. Added and Updated browser definition files.
. ASP.Net Routing.
. The ability to Persist Selected rows in data Control.
. More control over rendered HTML in FormView and ListView Controls.
. Filtering Support for datasource Controls.


Q. What is machine.config file and how do you use it in ASP.Net 4.0?

Ans. Machine.Config file is found in the "CONFIG" subfolder of your .NET Framework install directory (c:\WINNT\Microsoft.NET\Framework\{Version Number}\CONFIG on Windows 2000 installations). It contains configuration settings for machine-wide assembly binding, built-in remoting channels, and ASP.NET.

In .the NET Framework 4.0, the major configuration elements(that use to be in web.config) have been moved to the machine.config file, and the applications now inherit these settings. This allows the Web.config file in ASP.NET 4 applications either to be empty or to contain just the following lines.


Q. What is RedirectPermanent in ASP.Net 4.0?

Ans. In earlier Versions of .Net, Response.Redirect was used, which issues an HTTP 302 Found or temporary redirect response to the browser (meaning that asked resource is temporarily moved to other location) which inturn results in an extra HTTP round trip. ASP.NET 4.0 however, adds a new RedirectPermanent that Performs a permanent redirection from the requested URL to the specified URL. and returns 301 Moved Permanently responses.
e.g. RedirectPermanent("/newpath/foroldcontent.aspx");


Q. How will you specify what version of the framework your application is targeting?

Ans. In Asp.Net 4 a new element "targetFramework" of compilation tag (in Web.config file) lets you specify the framework version in the webconfig file

It only lets you target the .NET Framework 4.0 and later verisons.


Q. What is the use of MetaKeywords and MetaDescription properties.

Ans. MetaKeywords and MetaDescription are the new properties added to the Page class of ASP.NET 4.0 Web Forms. The two properties are used to set the keywords and description meta tags in your page.
For e.g.



You can set these properties at run time, which lets you get the content from a database or other source, and which lets you set the tags dynamically to describe what a particular page is for.

You can also set the Keywords and Description properties in the @ Page directive at the top of the Web Forms page markup like,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Keywords="ASP,4.0,are keywords" Description="blah blah" %>


Q. What is Microsoft Ajax Library.

Ans. Microsoft Ajax Library is a client-only JavaScript library that is compatible with all modern browsers, including Internet Explorer, Google Chrome, Apple Safari, and Mozilla Firefox.Because the Microsoft Ajax Library is a client-only JavaScript library, you can use the library with both ASP.NET Web Forms and ASP.NET MVC applications. You can also create Ajax pages that consist only of HTML.


Q. What are the Changes in CheckBoxList and RadioButtonList Control ?

Ans. In ASP.NET 4, the CheckBoxList and RadioButtonList controls support two new values for the RepeatLayout property, OrderedList(The content is rendered as li elements within an ol element) and UnorderedList(The content is rendered as li elements within a ul element.)
For more info see : Specify Layout in CheckBoxList and RadioButtonList Control - ASP.Net 4


Q. Whats Application Warm-Up Module?

Ans. We can set-up a Warm-Up module for warming up your applications before they serve their first request.Instead of writing custom code, you specify the URLs of resources to execute before the Web application accepts requests from the network. This warm-up occurs during startup of the IIS service (if you configured the IIS application pool as AlwaysRunning) and when an IIS worker process recycles. During recycle, the old IIS worker process continues to execute requests until the newly spawned worker process is fully warmed up, so that applications experience no interruptions or other issues due to unprimed caches.

Monday, February 6, 2012

Html Raw of Asp.net MVC 3 with Razor view engine

Today, I'm posting about HTML Raw of MVC3 Razor View engine.

HtmlString IHtmlString and HttpUtlity.HtmlEncode in ASP.NET 4 are fantastic features.

Saving Content in Database, retrieve it dynamically on Front end page that is absolutely nice.

HtmlHelper.Raw Method wraps HTML markup using the IHtmlString class, which renders unencoded HTML.


   1:  public IHtmlString Raw(
2: string value 3: )



   1:  @{ var para = "<p>I am a parargraph</p>";}
   2:  @Html.Raw(para)

Sunday, February 5, 2012

LinkedList(Of T) Class C#

Today, I'm posting to about LinkedList class. LinkedList is one of System.Collections.Generic collection classes.

What LinkedList class can do:
You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional object allocated on the heap. LinkedList accepts null value.

Please note: LinkedList class doesn't support chaining, splitting, cycles or other features that can leave the list in inconsistent state. The list remains consistent on a signle thread. The Linkedlist supports multithread read.

Please see the following examples:



   1:  using System;

   2:  using System.Text;

   3:  using System.Collections.Generic;

   4:   

   5:  public class Example

   6:  {

   7:      public static void Main()

   8:      {

   9:          // Create the link list.

  10:          string[] words =

  11:              { "the", "fox", "jumped", "over", "the", "dog" };

  12:          LinkedList<string> sentence = new LinkedList<string>(words);

  13:          Display(sentence, "The linked list values:");

  14:          Console.WriteLine("sentence.Contains(\"jumped\") = {0}",

  15:              sentence.Contains("jumped"));

  16:   

  17:          // Add the word 'today' to the beginning of the linked list.

  18:          sentence.AddFirst("today");

  19:          Display(sentence, "Test 1: Add 'today' to beginning of the list:");

  20:   

  21:          // Move the first node to be the last node.

  22:          LinkedListNode<string> mark1 = sentence.First;

  23:          sentence.RemoveFirst();

  24:          sentence.AddLast(mark1);

  25:          Display(sentence, "Test 2: Move first node to be last node:");

  26:   

  27:          // Change the last node be 'yesterday'.

  28:          sentence.RemoveLast();

  29:          sentence.AddLast("yesterday");

  30:          Display(sentence, "Test 3: Change the last node to 'yesterday':");

  31:   

  32:          // Move the last node to be the first node.

  33:          mark1 = sentence.Last;

  34:          sentence.RemoveLast();

  35:          sentence.AddFirst(mark1);

  36:          Display(sentence, "Test 4: Move last node to be first node:");

  37:   

  38:   

  39:          // Indicate, by using parentheisis, the last occurence of 'the'.

  40:          sentence.RemoveFirst();

  41:          LinkedListNode<string> current = sentence.FindLast("the");

  42:          IndicateNode(current, "Test 5: Indicate last occurence of 'the':");

  43:   

  44:          // Add 'lazy' and 'old' after 'the' (the LinkedListNode named current).

  45:          sentence.AddAfter(current, "old");

  46:          sentence.AddAfter(current, "lazy");

  47:          IndicateNode(current, "Test 6: Add 'lazy' and 'old' after 'the':");

  48:   

  49:          // Indicate 'fox' node.

  50:          current = sentence.Find("fox");

  51:          IndicateNode(current, "Test 7: Indicate the 'fox' node:");

  52:   

  53:          // Add 'quick' and 'brown' before 'fox':

  54:          sentence.AddBefore(current, "quick");

  55:          sentence.AddBefore(current, "brown");

  56:          IndicateNode(current, "Test 8: Add 'quick' and 'brown' before 'fox':");

  57:   

  58:          // Keep a reference to the current node, 'fox',

  59:          // and to the previous node in the list. Indicate the 'dog' node.

  60:          mark1 = current;

  61:          LinkedListNode<string> mark2 = current.Previous;

  62:          current = sentence.Find("dog");

  63:          IndicateNode(current, "Test 9: Indicate the 'dog' node:");

  64:   

  65:          // The AddBefore method throws an InvalidOperationException

  66:          // if you try to add a node that already belongs to a list.

  67:          Console.WriteLine("Test 10: Throw exception by adding node (fox) already in the list:");

  68:          try

  69:          {

  70:              sentence.AddBefore(current, mark1);

  71:          }

  72:          catch (InvalidOperationException ex)

  73:          {

  74:              Console.WriteLine("Exception message: {0}", ex.Message);

  75:          }

  76:          Console.WriteLine();

  77:   

  78:          // Remove the node referred to by mark1, and then add it

  79:          // before the node referred to by current.

  80:          // Indicate the node referred to by current.

  81:          sentence.Remove(mark1);

  82:          sentence.AddBefore(current, mark1);

  83:          IndicateNode(current, "Test 11: Move a referenced node (fox) before the current node (dog):");

  84:   

  85:          // Remove the node referred to by current.

  86:          sentence.Remove(current);

  87:          IndicateNode(current, "Test 12: Remove current node (dog) and attempt to indicate it:");

  88:   

  89:          // Add the node after the node referred to by mark2.

  90:          sentence.AddAfter(mark2, current);

  91:          IndicateNode(current, "Test 13: Add node removed in test 11 after a referenced node (brown):");

  92:   

  93:          // The Remove method finds and removes the

  94:          // first node that that has the specified value.

  95:          sentence.Remove("old");

  96:          Display(sentence, "Test 14: Remove node that has the value 'old':");

  97:   

  98:          // When the linked list is cast to ICollection(Of String),

  99:          // the Add method adds a node to the end of the list.

 100:          sentence.RemoveLast();

 101:          ICollection<string> icoll = sentence;

 102:          icoll.Add("rhinoceros");

 103:          Display(sentence, "Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':");

 104:   

 105:          Console.WriteLine("Test 16: Copy the list to an array:");

 106:          // Create an array with the same number of

 107:          // elements as the inked list.

 108:          string[] sArray = new string[sentence.Count];

 109:          sentence.CopyTo(sArray, 0);

 110:   

 111:          foreach (string s in sArray)

 112:          {

 113:              Console.WriteLine(s);

 114:          }

 115:   

 116:          // Release all the nodes.

 117:          sentence.Clear();

 118:   

 119:          Console.WriteLine();

 120:          Console.WriteLine("Test 17: Clear linked list. Contains 'jumped' = {0}",

 121:              sentence.Contains("jumped"));

 122:   

 123:          Console.ReadLine();

 124:      }

 125:   

 126:      private static void Display(LinkedList<string> words, string test)

 127:      {

 128:          Console.WriteLine(test);

 129:          foreach (string word in words)

 130:          {

 131:              Console.Write(word + " ");

 132:          }

 133:          Console.WriteLine();

 134:          Console.WriteLine();

 135:      }

 136:   

 137:      private static void IndicateNode(LinkedListNode<string> node, string test)

 138:      {

 139:          Console.WriteLine(test);

 140:          if (node.List == null)

 141:          {

 142:              Console.WriteLine("Node '{0}' is not in the list.\n",

 143:                  node.Value);

 144:              return;

 145:          }

 146:   

 147:          StringBuilder result = new StringBuilder("(" + node.Value + ")");

 148:          LinkedListNode<string> nodeP = node.Previous;

 149:   

 150:          while (nodeP != null)

 151:          {

 152:              result.Insert(0, nodeP.Value + " ");

 153:              nodeP = nodeP.Previous;

 154:          }

 155:   

 156:          node = node.Next;

 157:          while (node != null)

 158:          {

 159:              result.Append(" " + node.Value);

 160:              node = node.Next;

 161:          }

 162:   

 163:          Console.WriteLine(result);

 164:          Console.WriteLine();

 165:      }

 166:  }

 167:   

 168:  //This code example produces the following output:

 169:  //

 170:  //The linked list values:

 171:  //the fox jumped over the dog

 172:   

 173:  //Test 1: Add 'today' to beginning of the list:

 174:  //today the fox jumped over the dog

 175:   

 176:  //Test 2: Move first node to be last node:

 177:  //the fox jumped over the dog today

 178:   

 179:  //Test 3: Change the last node to 'yesterday':

 180:  //the fox jumped over the dog yesterday

 181:   

 182:  //Test 4: Move last node to be first node:

 183:  //yesterday the fox jumped over the dog

 184:   

 185:  //Test 5: Indicate last occurence of 'the':

 186:  //the fox jumped over (the) dog

 187:   

 188:  //Test 6: Add 'lazy' and 'old' after 'the':

 189:  //the fox jumped over (the) lazy old dog

 190:   

 191:  //Test 7: Indicate the 'fox' node:

 192:  //the (fox) jumped over the lazy old dog

 193:   

 194:  //Test 8: Add 'quick' and 'brown' before 'fox':

 195:  //the quick brown (fox) jumped over the lazy old dog

 196:   

 197:  //Test 9: Indicate the 'dog' node:

 198:  //the quick brown fox jumped over the lazy old (dog)

 199:   

 200:  //Test 10: Throw exception by adding node (fox) already in the list:

 201:  //Exception message: The LinkedList node belongs a LinkedList.

 202:   

 203:  //Test 11: Move a referenced node (fox) before the current node (dog):

 204:  //the quick brown jumped over the lazy old fox (dog)

 205:   

 206:  //Test 12: Remove current node (dog) and attempt to indicate it:

 207:  //Node 'dog' is not in the list.

 208:   

 209:  //Test 13: Add node removed in test 11 after a referenced node (brown):

 210:  //the quick brown (dog) jumped over the lazy old fox

 211:   

 212:  //Test 14: Remove node that has the value 'old':

 213:  //the quick brown dog jumped over the lazy fox

 214:   

 215:  //Test 15: Remove last node, cast to ICollection, and add 'rhinoceros':

 216:  //the quick brown dog jumped over the lazy rhinoceros

 217:   

 218:  //Test 16: Copy the list to an array:

 219:  //the

 220:  //quick

 221:  //brown

 222:  //dog

 223:  //jumped

 224:  //over

 225:  //the

 226:  //lazy

 227:  //rhinoceros

 228:   

 229:  //Test 17: Clear linked list. Contains 'jumped' = False

 230:  //



  


// ( reference to MSDN: msdn.microsoft.com/en-us/library/he2s3bh7.aspx)