Monday, July 27, 2009

Dotnet FAQ

What is the Caching in ASP.Net?
Caching is a technique of storing an in-memory copy of important and much used data/information to improve the performance of any software system. The idea is to place frequently used data in quickly accessed media. The ASP.Net runtime includes a key-value map of CLR objects called cache. This lives with the application and is available via the HttpContext and System.Web.UI.Page. Using cache is to some extent similar to using Session object. You can access items in the cache using an indexer and may control the lifetime of objects in the cache and set up links between the cached objects and their physical sources.


What are the type of caching in ASP.Net?
ASP.Net provides two types of caching which complement each other.
1. Output Caching: Output cache stores a copy of the finally rendered HTML page sent to the browser. When the next client requests for this page, the page is not actually run instead the cached copy of the HTML is sent thus saving time.
2. Data Caching: Data cache stores pieces of information like DataTable or DataSet retrieved from a database. Data caching is similar to application state, but it is more server friendly. Because, cache items could be removed from the server memory if it grows large and affects performance. Items can also be set to expire automatically.
The following types of caching are built on these two models.
1. Fragment caching: instead of caching the entire HTML page, you can cache a portion of it
2. Data source caching: this is built into the data source controls like—the SqlDataSource, ObjectDataSource and XmlDataSource. You need to configure the appropriate properties and the data source control manages the caching storage and retrieval.

What is Cross Page Posting? How is it done?
By default, ASP.Net submits a form to the same page. In cross-page posting, the form is submitted to a different page. This is done by setting the PostBackUrl property of the button(that causes postback) to the desired page. In the code-behind of the page to which the form has been posted, use the FindControl method of the PreviousPage property to reference the data of the control in the first page.

How can you change a Master Page dynamically at runtime?
To change a master page, set the MasterPageFile property of the @Page directive to point to the .master page during the PreInit page event.

What is use of the AutoEventWireup attribute in the Page directive of the ASP.Net?
The AutoEventWireUp is a boolean attribute that allows automatic wireup of page events when this attribute is set to true on the page. It is set to True by default for a C# web form whereas it is set as False for VB.Net forms. Pages developed with Visual Studio .NET have this attribute set to false, and page events are individually tied to handlers



What is a connection pool?
A connection pool is a collection of connections which are shared between the clients requesting one. Once the connection is closed, it returns back to the pool. This allows the connections to be reused.



What is the use of Master Pages in ASP.NET 2.0?
ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.

The ContentPlaceHolder control is where the page specific content will be placed. This master page is a template that will act as the base for all subsequent pages.

A master page is an ASP.NET file with the extension .master (for example, MySite.master) with a predefined layout that can include static text, HTML elements and server controls.

The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages. The @ Master directive can contain most of the same directives that a @ Control directive can contain. For example, the following master-page directive includes the name of a code-behind file, and assigns a class name to the master page.

What is smart navigation in ASP.NET Pages?
When a page is requested by an Internet Explorer 5 browser, or later, smart navigation enhances the users experience of the page by performing the following:
• Eliminating the flash caused by navigation.
• Persisting the scroll position when moving from page to page.
• Persisting element focus between navigations.
• Retaining only the last page state in the browsers history.
• Smart navigation is best used with ASP.NET pages that require frequent postbacks but with visual content that does not change dramatically on return. Consider this carefully when deciding whether to set this property to true.
Set the SmartNavigation attribute to true in the @ Page directive in the .aspx file. When the page is requested, the dynamically generated class sets this property.





What method do you use to explicitly kill a users session in ASP.Net?
The Session.Abandon() method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.





Explain the System.Data namespace in .Net Framework Class Library.
The System.Data namespace consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables developers to build components that efficiently manage data from multiple data sources. In a disconnected scenario, for example where a mobile application client connects to a database, extracts data, and then disconnects, ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The same ADO.NET model can be used in client applications, such as Windows Forms, in Web applications created with ASP.NET, in Web services, in daemon applications, or even in database trigger logic.





Explain the System.Diagnostics namespace in .Net Framework Class Library
The System.Diagnostics namespace provides classes that allow applications to interact with system processes, event logs, and performance counters.

Like the Process class provides functionality to monitor system processes across the network, and to start and stop local system processes.

The System.Diagnostics namespace also provides classes that allow you to debug your application and to trace the execution of your code through Trace and Debug classes.





Explain the System.DirectoryServices namespace in .Net Framework Class Library
The System.DirectoryServices namespace provides easy access to Active Directory from managed code. The namespace contains two component classes, DirectoryEntry and DirectorySearcher, which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the network size.

The classes in this namespace can be used with any of the Active Directory service providers. The current providers are: Internet Information Services (IIS), Lightweight Directory Access Protocol (LDAP), Novell NetWare Directory Service (NDS), and WinNT.





Explain the System namespace in .Net Framework Class Library
The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.

Other classes provide services supporting data type conversion, method parameter manipulation, mathematics, remote and local program invocation, application environment management, and supervision of managed and unmanaged applications.

Tuesday, July 21, 2009

ASPNet Optimzation Tips

Use Page.IsPostback to avoid unnecessary processing on a round trip.

CACHE data and page output whenever possible.

Turn OFF ViewState if not being used.
Ihe ViewState is configured at three levels which results in slow performance of the application,when it is Turned ON.

Minimize the amount and complexity of data stored in a session state.
The larger and complex the data is ,the higher the cost of serializing or deserializing of data.

Disable the Session when it is not using.
This can be done at the application level in the
"Machine.Config" file or at a page level.

Use SERVER.TRANSFER rather than Response.Redirect, if the WebPage is present in the same application. This makes the communication faster.

Use Exceptions in the code where necessary.
Exceptions reduce performance. Do not catch the exception itself before handling the condition.

Cache data and page output whenever possible.

Disable DEBUG mode before deploying the application.

Do a “PRE-BATCH" compilation.
To achieve this, request a page from the site. Avoid making changes to pages or assemblies that are there in the bin directory of the application. A changed page will only recompile the page. Any change to the bin directory will result in recompile of the entire application.

Use ASP.NET TRACE feature for efficient debugging instead of RESPONSE.WRITE.

Use Server Controls in appropriate circumstances.
Since ,they are expensive because they are server resources even though are they are very easy to implement.

IN-PROC option will provide better performance.
SQL SERVER option provides more reliability

Release the native resources as soon as the usage is over.
This will reduce performance issues, since by nature GC release them at a later point.
This results in appropriate utilization of resources by the other Requests.

AJAX In ASP.Net

Ajax stands for Asynchronous Javascript & XML. It is a web technology through which a postback from a client (browser) to the server goes partially, which means that instead of a complete postback, a partial postback is triggered by the Javascript XmlHttpRequest object. In such a scenario, web-application users won't be able to view the complete postback progress bar shown by the browser. In an AJAX environment, it is Javascript that starts the communication with the web server.

Ajax technology in a website may be implemented by using plain Javascript and XML. Code in such a scenario may tend to look little complex, for which the AJAX Framework in .NET can be embedded in ASP.NET web applications.

In addition to XML & Javascript, AJAX is also based on DOM - the Document Object Model technology of browsers through which objects of the browser can be accessed through the memory heap using their address