This section provides all possible ASP.Net 4.0 interview questions collected from various people from their experiences and various resources. Please always make sure to refer good books to find best answers and accuracy.
1 . What is new in Asp.Net
ASP.Net 4.0 has many improvements from previous versions such as
- Web.config File Refactoring
- Extensible Output Caching
- Auto-Start Web Applications
- Permanently Redirecting a Page by introducing a new method RedirectPermanent()
- Shrinking Session State to shrink session data
- Extensible Request Validation to avoid cross-site scripting (XSS) attacks by adding custom request-validation logic.
- Object Caching and Object Caching Extensibility by introducing a new assembly "System.Runtime.Caching.dll"
ASP.Net 4.0 also introduced many new features such as
2. How is Caching extended in asp.Net 4.0?
- jQuery Included with Web Forms and MVC: Built in JQuery support
- Content Delivery Network Support: Enables you to easily add ASP.NET Ajax and jQuery scripts to your Web applications. We can refence JQuery script over http like <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" >
- New Meta tags under HTML Head tag
- Enabling View State for Individual Controls
- Extended Browser Capabilities
- ASP.NET Chart Control to create visually compelling charts for complex statistical or financial analysis
- New Field Templates for URLs and E-mail Addresses
OutPut Cache in earlier versions of ASP.Net has a limitation - generated content always has to be stored in memory, and on servers that are experiencing heavy traffic, the memory consumed by output caching can compete with memory demands from other portions of a Web application.
ASP.NET 4 adds an extensibility point to output caching that enables you to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. This makes it possible to create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines.3. What is permanent redirecting and how do you implement it?
ASP.NET 4.0 introduces some SEO improvements. Response has now new method called RedirectPermanent(). This method performs same redirect as Response.Redirect() but it uses response code 301. You can find more information about HTTP response codes from HTTP 1.1 specification, chapter 10. Status Code Definitions.
Response.Redirect() returns 302 to browser meaning that asked resource is temporarily moved to other location. Permanent redirect means that browser gets 301 as response from server. In this case browser doesn’t ask the same resource from old URL anymore – it uses URL given by Location header.4. How do you implement custom output caching?
Create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type. You can then configure the provider in the Web.config file by using the new providers subsection of the outputCache element, as shown below: <caching> <outputCache defaultProvider="AspNetInternalProvider"> <providers> <add name="DiskCache" type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/> </providers> </outputCache> </caching>
Then specify the newly created and configured custom cache provider as below:<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>5. How do you implement ViewState for a control?
In ASP.NET 4, Web server controls include a ViewStateMode property that lets you disable view state by default and then enable it only for the controls that require it in the page.
The ViewStateMode property takes an enumeration that has three values: Enabled, Disabled, and Inherit. Enabled enables view state for that control and for any child controls that are set to Inherit or that have nothing set. Disabled disables view state, and Inherit specifies that the control uses the ViewStateMode setting from the parent control.
<asp:PlaceHolder ID="PlaceHolder1" runat="server" ViewStateMode="Disabled"> 6. How will the IDs for controls be managed in ASP.Net 4.0?
Disabled: <asp:Label ID="label1" runat="server" Text="[DeclaredValue]" /><br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server" ViewStateMode="Enabled">
Enabled: <asp:Label ID="label2" runat="server" Text="[DeclaredValue]" />
In ASP.Net 4.0 we can specify how to generate control ids using 'ClientIDMode' attribute instead of generating dynamically like container_controlidXXX.7. What are the different ClientIDModes we can set and how will they work?
The new ClientIDMode property lets you specify more precisely how the client ID is generated for controls. You can set the ClientIDMode property for any control, including for the page. Possible settings are the following:
This is equivalent to the algorithm for generating ClientID property values that was used in earlier versions of ASP.NET.
This specifies that the ClientID value will be the same as the ID without concatenating the IDs of parent naming containers. This can be useful in Web user controls. Because a Web user control can be located on different pages and in different container controls, it can be difficult to write client script for controls that use the AutoID algorithm because you cannot predict what the ID values will be.
This option is primarily for use in data controls that use repeating templates. It concatenates the ID properties of the control's naming containers, but generated ClientID values do not contain strings like "ctlxxx". This setting works in conjunction with the ClientIDRowSuffix property of the control. You set the ClientIDRowSuffix property to the name of a data field, and the value of that field is used as the suffix for the generated ClientID value. Typically you would use the primary key of a data record as the ClientIDRowSuffix value.
This setting is the default behavior for controls; it specifies that a control's ID generation is the same as its parent.