Saturday, December 1, 2007

Asp.net Interview Questions

1>Describe the role of inetinfo.exe, aspnet_isapi.dll and aspnet_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 to the actual worker process aspnet_wp.exe.

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

3>What methods are fired during the page load?
Init() - when the page is instantiatedLoad() - when the page is loaded into server memoryPreRender() - the brief moment before the page is displayed to the user as HTMLUnload() - when page finishes loading.

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

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

6> Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture
7>What’s the difference between Codebehind="MyCode.aspx.cs" and Src="MyCode.aspx.cs"?CodeBehind is relevant to Visual Studio.NET only.

8> 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.

9>Where do you add an event handler?
Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");

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

11> Explain the differences between Server-side and Client-side code?
Server-side code executes on the server. Client-side code executes in the client's browser.

12> 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-behind's 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.

13>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.

14>What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?
Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.

15>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.· There's 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.

16>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.

17>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.

18> 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.

19> 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.

20>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.

21> 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.

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

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

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

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

26>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.

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

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

29>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.
30> Which control would you use if you needed to make sure the values in two different controls matched?
CompareValidator control.
31> How many classes can a single .NET DLL contain?
It can contain many classes.

32> What is Viewstate?
Whatever you store in the view state travels back and forth making page downloads slower.
Serializing and deserializing a complex object could incur too much overhead.

view state vs. session
------------------------------------
Session State View State
Holds server resources? Yes No
Times out? Yes – after 20 minutes (default) No
Stores any .NET type? Yes No, limited support for: strings,Booleans, arrays, integers,ArrayList,
hashtable, custom TypeConverters
Increases "HTML payload"? No Yes


33>How Do I Enable View State?
You may do so on the machine, application, page and control level. First, you must have a server side form (form runat="server").By default view state is enabled.view state is enabled on the machine level it is enabled on the application, page and control level.To disable view state of an individual control set its EnableViewState to false:asp:label id="Label1" runat="server" enableviewstate="false"

DataGrid does not post back you can live without view state just fine. On the other hand, if the DataGrid has sorting or paging enabled you will want view state.Remember, DataGrid renders as a table with rows and cells being its child controls. View state is maintained for these child controls. The DataGrid has no memory of the datasource you bound it to! The datasource is NOT stored in the viewstate.You may also disable view state on an entire page by modifying the Page directive:%@ Page ... EnableViewState="false" %If you really wish you may also disable view state on the whole web application by adding the following line to your web.config:(pages enableviewstate="false")

Once again, view state is represented as a base64-encoded string. The keyword here is encoded. Not encrypted. Therefore if you were to decode it you would be able to gain insight of the workings of a web page. Maybe someone would be smart enough to store a credit card number in view state! This also means that someone may build their own page, pre-fill it and send it to your server (one-click attack) thus fooling it to believe it's dealing with a legitimate page. There's a simple yet effective way to counter this attack.By default ASP.NET builds a so-called Message Authentication Code (MAC) and appends it to the view state. When the page posts back ASP.NET recalculates the hash and compares it to the one that arrived with the view state string. If they are different it reverts to old control values. If you peek into your machine.config again you'll notice that MAC validation is on by default:It is strongly recommended that you keep MAC validation enabled at all times.
Protecting View State: Web Farm Scenario------------------------------------------machinekey validationkey="value,[IsolateApps]" decryptionkey="value,[IsolateApps]" validation="SHA1MD53DES"

AutoEventWireup in asp.net

AutoEventWireup

By default in VS.NET 2003 it would be "false".
AutoEventWireup in asp.net 2.0 by default true

If it's set to "True", the ASP.NET runtime does not require events to specify event handlers like Page_Load etc. When it is true VS.NET automatically wires up the event for you.All of this happens without explicit delegates or Handles clauses.

Saturday, November 10, 2007

Sql server interview Question

1.How to retreive the value of last identity has been updated in a database (SQL Server)?

SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.

SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Asp.Net Latest Interview Questions

1. Explain the life cycle of an ASP .NET page.

Ans :

Page: Init
Page: PreLoad
Page: Load
Page: PreRender
Page: Render
Page: Unload

2.Explain the .NET architecture?

The order starting from the bottom
1. CLR (Common Language Runtime)
2. .Net framework base classe
3. ASP.Net Web Form / Windows Form

3. What is abstract class?
Abstract class connot be instantiated instead it has to be inherited. The methods in abstract class can be overridetn in the child class.

4.What is difference between interface inhertance and class inheritance?

Class inheritance: copy attributes and operations defined in a super class into its subclass. We only add new attributes and operations specific to the sub class. A sub class may override a super class features (attributes and operations) by defining a feature with the same name.


Interface inheritance: inherit only the signature defined in an abstract operation. We prepare the different implementation of method in each concrete sub class. And we invoke them with the same signature.

5.What are the collection classes?
collection is the set of object instances of the same class.
The .NET Framework provides specialized classes for data storage and retrieval.
These classes provide support for stacks, queues, lists, and hash tables.

6.What inheritance does VB.NET support
VB .NET supports object-oriented inheritance (but not multiple inheritance).

7.What is a runtime host?
The common language runtime has been designed to support a variety of different types of applications, from Web server applications to applications with a traditional rich Windows user interface. Each type of application requires a runtime host to start it. The runtime host loads the runtime into a process, creates the application domains within the process, and loads user code into the application domains.
Runtime Host Description
ASP.NET
Loads the runtime into the process that is to handle the Web request. ASP.NET also creates an application domain for each Web application that will run on a Web server.

Microsoft Internet Explorer
Creates application domains in which to run managed controls. The .NET Framework supports the download and execution of browser-based controls. The runtime interfaces with the extensibility mechanism of Microsoft Internet Explorer through a mime filter to create application domains in which to run the managed controls. By default, one application domain is created for each Web site.

Shell executables
Invokes runtime hosting code to transfer control to the runtime each time an executable is launched from the shell.

8.Differences between application and session

Application state is a state where we hav the information that is global for the application,
where as
session state is a state which is maintained as a per-client basis.
whenever a user first accesses a page a session id is generated by asp.net.
that session id is then transmitted between the client and the server via Http either with the help of client-side cookies or encoded in a mangled sessions of the urls.
so the next time the users accesses,state associated with that session id can be viewed or modified

9.Will the following code execute successfully: response.write(’value of i=’+i);

10.What are the Difference between bstract base classes and Abstrat classes

An abstract class is one which cannot be instantiated; you can't create its objects like the way you do for concrete classes. But abstract classes can contain concrete as well as abstract methods (methods with no body). Besides, an abstract class can have all members concrete.

If an abstract class contains atleast one method which is abstract (or pure virtual function in C++), then we call it as an Abstract Base Class (ABC).

11.Explain serialization?
Serialization is the process of storing an object, including all of its public and private fields, to a stream. Deserialization is the opposite – restoring an object's field values from a stream.

12.What is the difference between overloading and overriding ? how can this be .NET

Over Loading and Overriding :--

In a class if two method is having the same name and different signature,its known as overloading in Object oriented concepts.

For eg Take the case of a Shape Class. having a method with a name DrawShape();

This method has two definitins with different parameters.



1. public void DrawShape(int x1, int y1,int x2,int y2)
{
// draw a rectangle.
}

2. public void DrawShape(int x1,int y1)
{

// draw aline.
}


These two method does different operation based on the parameters. so through the same
interface (method name) the user is will be able to do multiple tasks (draw line and rectangle).This is called over loading, and is an example of polymorphism.

Overriding :--

Overriding means, to give a specific definition by the derived class for a method implemented in the base class.

For eg.



Class Rectangle
{

publc void DrawRectangle()
{
// this method will draw a rectangle.
}

}


Class RoundRectangle : Rectanlge
{

public void DrawRectangle()
{

//Here the DrawRectangle() method is overridden in the
// derived class to draw a specific implementation to the
//derived class, i.e to draw a rectangle with rounded corner.

}
}



In the above example, the RoundedRectangle class needs to have its own
implementation of the DrawRectangle() method,i.e to draw a rectangle with
rounded corners. so it overloaded and gave it implementation.

13.Explain friend and protected friend?

Friend/Internal - Method, Properties in a class can be accessed by all the classes within that particular assembly.

Protected Friend/Protected Internal - Methods, Properties can be accessed by all the classes in that particular assembly and also by the child classes of that particular class.