The System Info
. . .
.
ASP.NET Interview Questions

GENERAL QUESTIONS

What is ASP.Net ?
ASP stands for Active Server Pages. ASP is an open, compile-free application environment in which you can combine HTML, scripts, and reusable ActiveX server components to create dynamic and powerful Web-based business solutions. Active Server Pages enables server side scripting for IIS with native support for both VBScript and JScript.

ASPs are Web pages that contain server-side scripts in addition to the usual mixture of text and HTML tags. Server-side scripts are special commands you put in Web pages that are processed before the pages are sent from the server to the web-browser of someone whos visiting your website. All ASP pages are given a .aspx extension. The servers that support ASP are Internet Information Server (IIS) & Microsoft Personal Web Server. Unline normal HTML pages you can view ASP pages without running a web server.

When a ASP.net page is compiled its translated into MSIL.

What is Client side and Server side scripting ?
Client Side scripting: HTML is a language that provides formatting of static textual data. However it provides no true interactivity other than allowing the user to navigate from one page to another. Client side scripting enables embedding of limited programming instructions within a web page and this is performed at the client end. JavaScript and VBScript are two languages that allow you to embed client side scripting code into your static HTML files. The syntax of JavaScript is similar to Java as VBScript is similar to VB. The script is included in the tags.

Server Side scripting: When the browser makes a request for a file ending with the .ASP file extension, IIS knows to bring ASP.DLL into play to interpret the ASP code in the file. Once interpreted, the results of this code are placed into the document, which is a simple HTML document before it is sent to the user.

How does ASP.DLL know which code to interpret?
The answer to this question is the key to executing code on the server. ASP.DLL interprets all code in a file (with the .ASP file extension) thats delimited with

<?php

?>

as being ASP code.

What is the global.asax file ?
Global.asax is a file used to declare application-level events and objects. Global.asax is the ASP.NET extension of the ASP Global.asa file. Code to handle application events (such as the start and end of an application) reside in Global.asax. Such event code cannot reside in the ASP.NET page or web service code itself, since during the start or end of the application, its code has not yet been loaded (or unloaded).

Global.asax is also used to declare data that is available across different application requests or across different browser sessions. This process is known as application and session state management. The Global.asax file must reside in the IIS virtual root.

Events and state specified in the global file are then applied to ASP.NET all resources housed within the web application. If, for example, Global.asax defines a state application variable, all .aspx files within the virtual root will be able to access the variable. Like an ASP.NET page, the Global.asax file is compiled upon the arrival of the first request for any resource in the application. The similarity continues when changes are made to the Global.asax file; ASP.NET automatically notices the changes, recompiles the file, and directs all new requests to the newest compilation. A Global.asax file is automatically created when you create a new web application project in the VS.NET IDE.

Global.asax files consist of the following elements:

1. Event Declarations: Define event delegates, such as OnStart (), that are global to an application.
2. Application Directives: Compiler-specific settings such as import statements.
3. Object Tag Declarations: Instances of objects that are globally accessible (state application variables).

Have you used the Visual Studio IDE? What are its features ?
Visual Studio .NET offers many advantages to the .NET developer, including: A modern interface, using a tabbed document layout for code and layout screens, and dockable toolbars and information windows.

· Convenient access to multiple design and code windows.
· WYSIWYG (What You See Is What You Get) visual design of Windows and Web Forms.
· Code completion, which allows you to enter code with fewer errors and less typing. · Intellisense, which pops up help on every method and function call as you type, providing the types of all parameters and the return type.

· Dynamic, context-sensitive help, which allows you to view topics and samples relevant to the code you are writing at the moment. You can also search the complete SDK library from within the IDE.

· Immediate flagging of syntax errors, which allows you to fix problems as they are entered.
· A Start Page, which provides easy access to new and existing projects.
· The same code editor for all .NET languages, which shortens the learning curve. Each language can have specialized aspects, but all languages benefit from shared features, such as incremental search, code outlining, collapsing text, line numbering, color-coded keywords, etc.
· An HTML editor, which provides both Design and HTML views that update each other in real time.
· A Solution Explorer, which displays all the files comprising your solution (which is a collection of projects) in an outline.
· A Server Explorer, which allows you to log on to servers to which you have network access, access the data and services on those servers, and perform a variety of other chores.

· An integrated Debugger, which allows you to step through code, observes program runtime behavior, and set breakpoints, even across multiple languages and multiple processes.

· Customization capability, which allows you to set user preferences for IDE appearance and behavior.
· Integrated build and compile support.
· Integrated support for source control software.
· A built-in task list.

What are web services ? What is the significance of WSDL ?
Web services allow access to software through standard web protocols such as HTTP and SMTP. They enable software to interact with a wider range of clients. Web services can be consumed by any application that understands how to parse an XML. XML is the key technology used in web services.

Microsoft .net web services support three protocols HTTP GET, HTTP POST and SOAP (Simple Object Access Protocol).

For the clients to interact with the web services there must be a description of the method calls or interface that the web service supports. This web service description document is found in the XML schema called as WSDL (Web services description language). Any WSDL capable SOAP client can use the WSDL file to get a description of the web service and invoke methods on the service.

What are directives ? Which are the directives used in ASP ?
Directives are used to pass optional settings to the ASP.NET pages and compilers. They typically have the following syntax: <%@ directive attribute=value [attribute=value] %> Directives are typically located at the top of the appropriate file, although that is not a strict requirement. For example, Application directives are at the top of the global.asax file, and Page directives are at the top of the .aspx files. Application directive: The Application directive is used to define application-specific attributes. It is typically the first line in the global.asax file. Assembly directive: The Assembly directive links an assembly to the application or page at parse-time. The Assembly directive is contained in either the global.asax file, for application-wide linking, or in a page (.aspx) or user control (.ascx) file, for linking to a specific page or user control. There can be multiple Assembly directives in any file. Each Assembly directive can have multiple attribute/value pairs. Control directive: The Control directive is used only with user controls and is contained in user control files (.ascx). There can only be a single Control directive per .ascx file. Import directive: The Import directive imports a namespace into a page, user control, or application, making all the classes and namespaces of the imported namespace available. Page directive: The Page directive is used to define attributes for the page parser and compiler specific to the page (.aspx) file. There can be no more than one Page directive for each page file. Each Page directive can have multiple attributes.

What is ISAPI ?
Microsoft introduced an alternative to CGI, the Internet Server Application Programming Interface (or ISAPI). ISAPI addresses one of the most limiting features of CGI applications. Each time a client requests the execution of a CGI application, the web server executes a separate instance of the application, sends in the users requesting information, and serves the results of the CGI applications processing to the client. The problem with this approach is that a separate CGI application is loaded for each request. This can be quite a drain on the servers resources if there are many requests for the CGI application.

ISAPI alleviates this problem by relying on dynamic link libraries (DLLs). Each ISAPI application is in the form of a single DLL that is loaded into the same memory space as the web server upon the first request for the application. Once in memory, the DLL stays in memory, answering user requests until it is explicitly released from memory. This increased efficiency in memory usage comes at a cost. All ISAPI DLLs must be thread-safe so that multiple threads can be instantiated into the DLL without causing problems with the applications function. ISAPI applications are normally faster than their equivalent CGI applications because the web server does not have to instantiate a new application every time a request is made. Once the ISAPI application DLL is loaded into memory, it stays in memory. The web server does not need to load it again

Explain the Application object ?
The Application object can store information that persists for the entire lifetime of an application (a group of pages with a common root). Generally, this is the whole time that the IIS server is running. This makes it a great place to store information that has to exist for more than one user (such as a page counter). The downside of this is that since this object isnt created anew for each user, errors that may not show up when the code is called once may show up when it is called 10,000 times in a row. In addition, because the Application object is shared by all the users, threading can be a nightmare to implement. You can use the Application object to share information among all users of a given application. An ASP-based application is defined as all the .asp files in a virtual directory and its subdirectories. Because the Application object can be shared by more than one user, there are Lock and Unlock methods to ensure that multiple users do not try to alter a property simultaneously.

What is the server object ?
The Server object provides several miscellaneous functions that you can use in your Active Server Page applications. Although most of its methods are seldom used, one method, the CreateObject method, and the Server objects single property, ScriptTimeout, are invaluable. You will use these in many of your scripts.

The Server object, as its name implies, represents the web server itself, and much of the functionality it provides is simply functionality the web server itself uses in the normal processing of client requests and server responses.

ScriptTimeout
Server.ScriptTimeout [= lngNumSeconds]
Specifies the maximum amount of time the web server will continue processing your script. If you do not set a value for this property, the default value is 90 seconds.

CreateObject
Set objMyObject = Server.CreateObject(strProgId)
Instantiates an object on the server. Once instantiated, this objects properties and methods can be used just as you can use the properties and methods of the objects that come with ASP. The DLLs from which these objects are instantiated must be installed and registered on the web server machine separately from your installation of IIS.

What is the use of the session object ?
You can use the Session object to store information needed for a particular user-session. Variables stored in the Session object are not discarded when the user moves between pages in the application; instead, these variables persist for the entire user-session. The Web server automatically creates a Session object when a Web page from the application is requested by a user who does not already have a session. The server destroys the Session object when the session expires or is abandoned. One common use for the Session object is to store user preferences. For example, if a user indicates that they prefer not to view graphics, you could store that information in the Session object. Note Session state is only maintained for browsers that support cookies.

What are HTML server controls and Web controls ?
HTML Server controls: HTML elements are completely client-based; the server has no knowledge of any of these controls. A browser knows what <input type="text"> is supposed to look like and renders it accordingly. HTML server controls are server-side elements. Theyre objects that are created on the server, with properties, methods, and events that you can handle. They generate HTML for the browser to display. HTML server controls are very easy to create.simply add the runat="server" attribute to any HTML element. Every HTML element has a corresponding HTML server control.

<input type="text" id="MyTextBox" runat="server" /> Once you turn an HTML element into an HTML server control, every attribute of the element can be modified through code. Web controls: Web server controls are similar to HTML server controls. Theyre created on the server and allow you to build complex user interfaces easily. They require the runat="server" attributes to work correctly. They also provide rich programmatic capabilities. Unlike HTML server controls, however, Web controls dont necessarily map one-to-one to HTML elements and can represent more complex UI elements.


What are Web Forms ?
Web forms are very similar to traditional HTML forms. The difference is that Web forms are server-based, meaning you create the user elements on the server. The server has complete knowledge of what the interface looks like, what it can do what data it expects, and so on.
Web forms pages are divided into two parts: the visual elements and the accompanying UI logic. These two components are completely separate from each other conceptually, and they can be physically located anywhere you want. Typically, both parts are contained within one .aspx file.

The System.Web.UI namescape defines classes and interfaces used in constructing nd rendering elements on a Web form. The most important class in the System.Web.UI is the Control class which defines the properties, methods and events that are common in all server controls in the WebForm framework. Another important class in this namespace is Page which is a derivative of the Control Class. All ASP.NET web pages are instances of derivatives of the Page Class. To have an extensible framework, the System.Web.UI namespace also includes the UserControl class which is similar to Page class except that it is mainly used as the base class for user controls.


BASIC QUESTIONS

What are some ways to manage state in an ASP.Net application?
Session objects, Application objects, ViewState, cookies, hidden form fields.

What does the "EnableViewState" property do? Why would I want it on or off?
It allows page objects to save their state in a Base64 encoded string in the page HTML. One should only have it enabled when needed because it adds to the page size and can get fairly large for complex pages with many controls. (It takes longer to download the page).

What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?
Server.Transfer transfers excution directly to another page. Response.Redirect sends a response to the client and directs the client (the browser) to load the new page (it causes a roundtrip). If you dont need to execute code on the client, Transfer is more efficient.

How can I maintain Session state in a Web Farm or Web Garden?
Use a State Server or SQL Server to store the session state.

What base class do all Web Forms inherit from?
The Page class.

What does WSDL stand for? What does it do?
WDSL (Web Services Description Language). It describes the interfaces and other information of a web service.

Which WebForm Validator control would you use if you needed to make sure the values in two different WebForm controls matched?
CompareValidator Control

What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?
You must set the DataSource property and call the DataBind method.


ADVANCED QUESTIONS

Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.

What’s the difference between Response.Write() andResponse.Output.Write()?
Response.Output.Write() allows you to write formatted output.

What methods are fired during the page load?
Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.

When during the page processing cycle is ViewState available?
After the Init() and before the Page_Load(), or OnLoad() for a control.

What namespace does the Web page belong in the .NET Framework class hierarchy?
System.Web.UI.Page

Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture

What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
CodeBehind is relevant to Visual Studio.NET only.

What’s a bubbled event?
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

Suppose you want a certain ASP.NET function executed on MouseOver for a certain button. Where do you add an event handler?
Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");

Explain what a diffgram is, and a good use for one?
The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. A good use is reading database data to an XML file to be sent to a Web Service.

Whats MSIL, and why should my developers need an appreciation of it if at all?
MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

Which method do you invoke on the DataAdapter control to load your generated dataset with data?
The Fill() method.

Can you edit data in the Repeater control?
No, it just reads the information from its data source.

Which template must you provide, in order to display data in a Repeater control?
ItemTemplate.

How can you provide an alternating color scheme in a Repeater control?
Use the AlternatingItemTemplate.

What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
You must set the DataSource property and call the DataBind method.

What base class do all Web Forms inherit from?
The Page class.

Name two properties common in every validation control?
ControlToValidate property and Text property.

Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
DataTextField property.

Which control would you use if you needed to make sure the values in two different controls matched?
CompareValidator control.

How many classes can a single .NET DLL contain?
It can contain many classes.

Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
Valid answers are:
· A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· Theres no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the data.
· You can store many edits in a DataSet, and write them to the original data source in a single operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.

What is the Global.asax used for?
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

What are the Application_Start and Session_Start subroutines used for?
This is where you can set the specific variables for the Application and Session objects.

Can you explain what inheritance is and an example of when you might use it?
When you want to inherit (use the functionality of) another class. Example: With a base class named Employee, a Manager class could be derived from the Employee base class.

Whats an assembly?
Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN

Describe the difference between inline and code behind?
Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

What data types do the RangeValidator control support?
Integer, String, and Date.

Explain the differences between Server-side and Client-side code?
Server-side code executes on the server. Client-side code executes in the clients browser.

What type of code (server or client) is found in a Code-Behind class?
The answer is server-side code since code-behind is executed on the server. However, during the code-behinds execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser. But just to be clear, code-behind executes on the server, thus making it server-side code.

Should user input data validation occur server-side or client-side? Why?
All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.


STATE MANAGEMENT QUESTIONS

What is ViewState?
ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used the retain the state of server-side objects between postabacks.

What is the lifespan for items stored in ViewState?
Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

What does the "EnableViewState" property do? Why would I want it on or off?
It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

What are the different types of Session state management options available with ASP.NET?
ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the web server. This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server. Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.


WEB SERVICE QUESTIONS

What is the transport protocol you use to call a Web service?
SOAP (Simple Object Access Protocol) is the preferred protocol.

A Web service can only be written in .NET? True or False
False

What does WSDL stand for?
Web Services Description Language.

To test a Web service you must create a Windows application or Web application to consume this service? True or False
False, the web service comes with a test page and it provides HTTP-GET method to test.

.
. . .
© 2008 TheSystemInfo. All Rights Reserved.
THE DATA IS FURNISHED, "AS IS" WITHOUT ANY WARRANTY OF ANY KIND, AND THESYSTEMINFO HEREBY DISCLAIM ALL WARRANTIES, EXPRESS, IMPLIED OR STATUTORY INCLUDING, WITHOUT LIMITATION, ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND ANY WARRANTIES AS TO NON-INFRINGEMENT, AND IN NO EVENT SHALL THESYSTEMINFO BE LIABLE FOR COSTS OF PROCURING SUBSTITUTE GOODS. IN NO EVENT WILL THESYSTEMINFO BE LIABLE FOR ANY INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY, OR OTHER DAMAGES WHETHER OR NOT THESYSTEMINFO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.