Monday 7 May 2012

Asp.Net 4.0 Interview Questions And Answers

1. What is main focus in Microsoft’s Latest ASP.NET 4.0?
 
Ans.The focus of Microsoft’s latest ASP.NET 4.0 has mainly been on improving the performance and Search-engine Optimization (SEO).

2. What are the improvements Microsoft has done in AJAX Library for ASP.NET 4.0?

Ans.
Following are some major improvements in the AJAX Library in ASP.NET 4.0.

Script Loader: The new script loader control enable developers to load all the required scripts only once, thereby eliminating the unnecessary subsequent requests to the server. It supports the ‘lazy load’ pattern which loads scripts only when necessary, and loads scripts in combination, in order to increase the performance of loading a page. It also supports the jQuery script and custom scripts.
JQuery Integration: ASP.NET 4.0 extensively supports the integration for jQuery by mixing the jQuery and Ajax plug-ins seamlessly.
Client Data Access: By using predefined client controls inside the Ajax Library, developers can easily build asynchronous data-driven applications. For example client DataView control will display one or more records by consuming a WCF service. All the relevant time-consuming operations will be handled by the Ajax library asynchronously.

3. What is Web.config File Refactoring provided in ASP.NET 4.0?

Ans.
The Web.config file that contains configuration information for a Web application has grown considerably over the past few releases of the .NET Framework as new features have been added.
In .the .NET Framework 4, the major configuration elements have been moved to the machine.config file, and applications now inherit these settings. This allows the Web.config file in ASP.NET 4 applications to be empty or to specify only which version of the framework the application is targeting, as shown in the following example:
<?xml version="1.0"?>
    <configuration>
        <system.web>
           <compilation targetFramework="4.0" />
        </system.web>
    </configuration>
4. What is Output Cache Extensibility in ASP.NET 4.0?

Ans.
The main limitation in Output Cache feature in previous versions of ASP.NET is that cached content always had to be stored in-memory. With ASP.NET 4.0 we can extend caching by using Output Cache Providers. We can create ‘Output Cache Providers’ that store the cache content to any persistence mechanism such as databases, disk, cloud storage and distributed cache engines.
To create a custom output-cache provider, a class which derived from System.Web.Caching.OutputCacheProvider has to be created in ASP.NET 4.0. There are four public methods which you have to override in order to provide your own implementation for add, remove, retrieve and update functionality. Also, the output-cache provider has to be registered in theweb.config.
<?xml version="1.0"?>
    <configuration>
        <system.web>
           <outputCache defaultProvider="DemoCache">
               <providers>
                    <add name="DemoCache" type="DemoCacheNamespace, DemoCacheClass" />
                </providers>
            </outputCache>
        </system.web>
    </configuration>
When you use OutputCache like following it will automatically take the default cache provider that is defined in the configuration file.
<%@ OutputCache Duration="60" VaryByParam="None" %>
Or you can also give provider at the time of using OutputCache like following.
<%@ OutputCache Duration="60" VaryByParam="None" providerName="DemoCache" %>
5. How Auto-Start Web Application is achieved in ASP.NET 4.0?

Ans. Scenario in Previous Versions of ASP.NET:
Most application requires initial data load or caching operations to be done before serving the client requests. Typical this happens only when the first user request a page. However, often developers and web administrators write fake requests to keep the application alive to increase the response time.
Resolution: To address this issue in ASP.NET 4.0 we can configure “Application Pool” worker process by setting the startMode attribute to “AlwaysRunning” in the applicationHost.config file which is normally situated at “C:\Windows\System32\inetsrv\config\” as shown in following sample code.
<applicatioPools>
     <add name="appProc" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
</applicatioPools>
6. What is advantage of Response.RedirectPermanent over Response.Redirect?

Ans.
For old URLs in previous versions of ASP.NET we can use Response.Redirect method to redirect user to new URL. The problem with it is causing extra round-trip to server to access old URLs and thus decreasing page rank in search engines.
Respnse.RedirectPermanent is using HTTP 301(Moved Permanently) internally to handle requests. This will enable search-engines to index URLs and content efficiently and thus improve the page rankings.
7. How we can use mechanism “Session State Compression” in ASP.NET 4.0?
Ans.
When we store session data in “OutProc” mode that is in state server or SQL server or anywhere else except in memory, we need to serialize our data before storing and deserialize data before retrieving, which will take significant time if the data that we are storing grows and also increase latency of the application.
In ASP.NET 4.0 we can compress data before serializing and decompress before deserializing the data. For defining the compression we need to set compressionEnable attribute to true while setting sessionState properties in web.config configuration file as shown in following demo code.
<sessionState mode="SqlServer" sqlConnectionSting="Your connection string for sql server"
allowCustomSqlDatabase="true" compressionEnable="true" />
Here the session state data will be serialized/deserialized using Session.IO.Compression.GZipStream.

8. In ASP.NET 4.0 how you can expand the range of allowable URLs?

Ans.
Upto foreversions of ASP.NET URLs are limited to 260 characters in length, based on NTFS file path limit. You can now increase(or decrease) this limit according to your requirement using two new attributes of the httpRuntime configuration element.
<httpRuntime maxRequestPathLength="260" maxQueryStringLength="2048" />
9. How you can restrict following characters in URLs of your web application?
<&*%;:\?>

Ans.
In ASP.NET 4.0 you can customize the set of valid characters using new requestPathInvalidChars attribute of the httpRuntime configuration element.
<httpRuntime requestPathInvalidChars="&lt;,&gt;,*,%,&amp;,:,;,\,?" />
10. What is new syntax for encoding string, which is in previous versions like following.
<strong><% =Server.HtmlEncode(content) %>
</strong>

Ans. We can use colon(:) after opening code segment in view as shown below.
<%: content %>
11. Is it possible to set ViewState for individual control in ASP.NET 4.0? If yes then how you could achieve it?
 
Ans. Yes, it is possible to set ViewState for individual control in ASP.NET 4.0. In each web control new attribute ViewStateMode property included. You can set Enabled, Disabled or Inherits to this property.

12. Which are the two properties given by ASP.NET 4.0 to give meta information at page level?
Ans.
ASP.NET introduces MetaKeywords and MetaDescription property to Page object, which you can use in code behind to define the meta information at page level as shown in below sample.
void Page_Load(Object sender, EventArgs e)
{
     Page.MetaDescription = "ASP.NET 4.0 New Features Interview Questions";
     Page.MetaKeywords = "ASP.NET 4.0 New Features, Interview Questions";
}

13. What is the feature that is supported by ASP.NET 4.0 for user friendly and meaningful URLs?
 
Ans. ASP.NET 4.0 supports built in support for URL Routing. This can make site more user friendly and site content more discoverable by search engines. It is also easy to remember and while bookmarking.
Following example shows URL without using Routing mechanism of ASP.NET 4.0.
http://website/products.aspx?categoryid=12
After using Routing mechanism of ASP.NET 4.0, above URL becomes as follow.
http://website/products/software
For mapping above URL to the list of products based on category, we need to map our route using new method MapPageRoute of class Route as shown in following examples.
Application_Start(object sender, EventArgs e)   {
     RouteTable.Routes.MapPageRoute("ProductsRoute",
         "product/{prodId}", "~/products.aspx");
}

14. How predictable cliend IDs generated in ASP.NET 4.0 server controls?
 
Ans. ASP.NET 4 now supports a new ClientIDMode property for server control.
This property indicates how the Client ID should be generated to a particular control
when they render. Client ID has been an important property of the server controls
recently—especially with the success of jQuery and other Ajax scripting technologies.
The ClientIDMode property has four values;
* AutoID – This renders the output as it was before (example: ctl00_ContentPlaceholder1_ListView1_ctrl0_Label1)
* Predictable (Default)– Trims all “ctl00” strings in the Client Id property.
* Static – Full control over the Client ID (developer can set the Client Id and it will not be changed after the control renders)
* Inherit – Allow control to inherit the behavior from its parent control

15. What are the different ways you can set Client ID property in ASP.NET 4.0?
 
Ans. There are four different ways you can set Client ID in ASP.NET 4.0 which are as
follows.
* Directly on individual control (On the container control. (All the child controls will inherit the settings from parent/container control)
* Page or User Control level using <%@ Page%> or <%@ Control %> directives.
* Directly in the web.config file. All the controls within the web application will inherit the settings.

16. What is role of ClientIDRowSuffix for data bound controls in ASP.NET 4.0?
 
Ans. Once we set the relevant databound property to ClientIDRowSuffix, the value will be added as a suffix to individual row elements. The example of which is as follow.
<asp:DataList ID="DataList1" ClientIDRowSuffix="State" runat="server">
</asp:DataList>
The state value will be added as suffix to each data row element as follows.
<ul>
     <li ID="John_NY">
          John
     </li>
     <li ID="Brian_CA">
          Brian
     </li>
</ul>

2 comments:

  1. Great Work !!! Thanks for sharing. Short n Sweet. Keep up with your Good work. All the Best !

    ReplyDelete