Friday 1 March 2013

ASP.NET Interview Questions Part II



1 What data type does the RangeValidator control support?
Integer,String and Date.

2 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 event handlers, allowing the main DataGrid event handler to take care of its constituents.

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

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

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

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

7 What’s the difference between Response.Write( ) andResponse.Output.Write( )?
The latter one allows you to write formattedoutput.

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

9 .NET is Compile Time OR RunTime Environment?
.Net’s framework has CLS,CTS and CLR.CTS checks declartion of types at the time when u write code and CLS defines some rules and restrictions.and CLR comile everything at runtime with following benefits: Vastly simplified development Seamless integration of code written in various languages Evidence-based security with code identity Assembly-based deployment that eliminates DLL Hell Side-by-side versioning of reusable components Code reuse through implementation inheritance Automatic object lifetime management Self describing objects

10 What’s wrong with a line like this? DateTime.Parse(myString)
the result returned by this function is not assigned to anything, should be something like varx = DateTime.Parse(myString)

11 Is string a value type or a reference type?
Answer1:
String is Reference Type.
Value type – bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short,strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type – class, delegate, interface, object, string
Reference types are stored in the Heap
Answer2:
Yes String is reference type. C# gives two types of variable reference and value type. string and object are reference type.

12 How would one do a deep copy in .NET?
Answer1:   System.Array.CopyTo( ) – Deep copies an Array
Answer2:          
 The First Approach.
1.Create a new instance.
2.Copy the properties from source instance to newly created instance.
[Use reflection if you want to write a common method to achive this]

The Second Approach.
1. Serialize the object and deserialize the output.
: Use binary serialization if you want private variables to be copied.
: Use xml Serialization if you dont want private variable to be copied.

13 What is the difference between a.Equals(b) and a == b?
Answer1: a=b is used for assigning the values (rather then comparison) and a==b is for comparison.
Answer2: a == b is used to compare the references of two objects a.Equals(b) is used to compare two objects
Answer3: A equals b à copies contents of b to a               a == b à checks if a is equal to b
Answer4: Equals method compares both type and value of the variable, while == compares value.
int a = 0;
bool b = 0
if(a.Equals(b))
Answer5: a.Equals(b) checks whether the Type of a is equal to b or not! Put it in another way,
Dim a As Integer = 1
Dim b As Single = 1
a.Equals(b) returns false. The Equals method returns a boolean value.
a == b is a simple assignment statement.
Answer6: a.equals(b) will check whether the “b” has same type as “a” has and also has the same data as “a” has.   a==b will do the same thing.
if you have done this in c++ under “operator overloading” than you guys must be aware of this sytaxts. they are doing the same thing there is only sytaxtical difference.
let me explain it in different manner.
a==b : means compare “b” with “a”. always left hand side expression evaluated first so here in this case “a” (considered an object) will call the overloaded operator “=” which defines “Equals(object)” method in it’s class. thus, ultimately a.equals(b) goanna called.
so the answer is: both will perform the same task. they are different by syntaxt
Answer7:  Difference b/w a==b,a.Equals(b)
a.Equals(b):
The default implementation of Equals supports reference equality only, but derived classes can override this method to support value equality.
For reference types, equality is defined as object equality; that is, whether the references refer to the same object. For value types, equality is defined as bitwise equality == :
For predefined value types, the equality operator (==) returns true if the values of its operands are equal, false otherwise. For reference types other than string, == returns true if its two operands refer to the same object. For the string type, == compares the values of the strings.

14 Contrast the use of an abstract base class against an interface?
Answer1:
In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes
Answer2:
Whether to Choose VB.NET/C#.
Both the languages are using same classes and namespaces. Once it compile and generates MSIL, there is no meaning of which language it was written. If you are Java/C++ programmer better to choose C# for same coding style otherwise you can choose VB.net.

15 What is the difference between Debug. Write and Trace. Write? When should each be used?
Answer1:
The Debug. Write call won’t be compiled when the DEBUG symbol is not defined (when doing a release build). Trace. Write calls will be compiled. Debug. Write is for information you want only in debug builds, Trace. Write is for when you want it in release build as well. And in any case, you should use something like log4net because that is both faster and better
Answer2:
Debug. Write & Trace. write – both works in Debug mode, while in Release Mode,Trace.write only will work .Try changing the Active Config property of Solution in Property page nd find the difference. Debug.write is used while debugging a project and Trace.write is used in Released version of Applications.

16 Why is catch(Exception) almost always a bad idea?
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

17 What does this do? gacutil /l | find /i “about”
Answer1This command is used to install strong typed assembly in GAC
Answer2:
gacutil.exe is used to install strong typed assembly in GAC. gacutil.exe /l is used to lists the contents of the global assembly cache. |(pipe) symbol is used to filter the output with another command. find /i “about” is to find the text “about” on gacutil output. If any lines contains the text “about” then that line will get displayed on console window.

18 What is FullTrust? Do GAC’ed assemblies have FullTrust?
Your code is allowed to do anything in the framework, meaning that all (.Net) permissions are granted. The GAC has FullTrust because it’s on the local HD, and that has FullTrust by default, you can change that using caspol

19 What is cyclomatic complexity and why is it important?
Cyclomatic complexity is a computer science metric (measurement) developed by Thomas McCabe used to generally measure the complexity of a program. It directly measures the number of linearly independent paths through a program’s source code.
The concept, although not the method, is somewhat similar to that of general text complexity measured by the Flesch-Kincaid Readability Test.
Cyclomatic complexity is computed using a graph that describes the control flow of the program. The nodes of the graph correspond to the commands of a program. A directed edge connects two nodes, if the second command might be executed immediately after the first command. By definition,
CC = E – N + P
where
CC = cyclomatic complexity
E = the number of edges of the graph
N = the number of nodes of the graph
P = the number of connected components.

20 What are PDBs? Where must they be located for debugging to work?
Answer1:
To debug precompiled components such as business objects and code-behind modules, you need to generate debug symbols. To do this, compile the components with the debug flags by using either Visual Studio .NET or a command line compiler such as Csc.exe (for Microsoft Visual C# .NET) or Vbc.exe (for Microsoft Visual Basic .NET).
Using Visual Studio .NET
1. Open the ASP.NET Web Application project in Visual Studio .NET.
2. Right-click the project in the Solution Explorer and click Properties.
3. In the Properties dialog box, click the Configuration Properties folder.
4. In the left pane, select Build.
5. Set Generate Debugging Information to true.
6. Close the Properties dialog box.
7. Right-click the project and click Build to compile the project and generate symbols (.pdb files).
Answer2:
A program database (PDB) file holds debugging and project state information that allows incremental linking of a Debug configuration of your program.
The linker creates project.PDB, which contains debug information for the project’s EXE file. The project.PDB contains full debug information, including function prototypes, not just the type information found in VCx0.PDB. Both PDB files allow incremental updates.
They should be located at bin\Debug directory

21 What is strong-typing versus weak-typing? Which is preferred? Why?
Strong type is checking the types of variables as soon as possible, usually at compile time. While weak typing is delaying checking the types of the system as late as possible, usually to run-time. Which is preferred depends on what you want. For scripts & quick stuff you’ll usually want weak typing, because you want to write as much less code as possible. In big programs, strong typing can reduce errors at compile time.

22 What is the difference between an EXE and a DLL?
An EXE can run independently, whereas DLL will run within an EXE. DLL is an in-process file and EXE is an out-process file

23 What is a Windows Service and how does its lifecycle differ from a “standard” EXE?
Windows Service applications are long-running applications that are ideal for use in server environments. The applications do not have a user interface or produce any visual output; it is instead used by other programs or the system to perform operations. Any user messages are typically written to the Windows Event Log. Services can be automatically started when the computer is booted. This makes services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer. They do not require a logged in user in order to execute and can run under the context of any user including the system. Windows Services are controlled through the Service Control Manager where they can be stopped, paused, and started as needed.

24 Describe the difference between a Thread and a Process?
Answer1:
Thread – is used to execute more than one program at a time.
process – executes single program
Answer2:
A thread is a path of execution that run on CPU, a proccess is a collection of threads that share the same virtual memory. A process have at least one thread of execution, and a thread always run in a process context.
Answer3:
The operating system creates a process for the purpose of running a program. Each process executes a single program. Processes own resources allocated by the operating system. Resources include memory, file handles, sockets, device handles, and windows. Processes do not share address spaces or file resources except through explicit methods such as inheriting file handles or shared memory segments, or mapping the same file in a shared way.
Threads allow a program to do multiple things concurrently. At least one thread exists within each process. If multiple threads can exist within a process, then they share the same memory and file resources.
Answer4:
Thread is a light weight process, which is initialized itself by a process. Light weigt processes does not loads resources required by it itself, these are loaded by its parent process which has generated it.

25 What is the difference between boxing and unboxing ?
Boxing allows us to convert value types to reference types. Basically, the runtime creates a temporary reference-type box for the object on heap.
Eg:
int i=20;
object o=i;

26 What is the standard you use to wrap up a call to a Web service?
Several possible answers depending on your interpretation of the quesiton, but I think you were aiming for SOAP (with the caveat that this is MS’s version of SOAP)

27 What tag do you use to add a hyperlink column to the DataGrid?
Depends on who’s definition of hyperlink your using. Manually a std html anchor tag (a) will work or you can use the micro-magical tag

28 What is State Management in .Net and how many ways are there to maintain a state in .Net? What is view state?
Web pages are recreated each time the page is posted to the server. In traditional Web programming, this would ordinarily mean that all information associated with the page and the controls on the page would be lost with each round trip.
To overcome this inherent limitation of traditional Web programming, the ASP.NET page framework includes various options to help you preserve changes — that is, for managing state. The page framework includes a facility called view state that automatically preserves property values of the page and all the controls on it between round trips.
However, you will probably also have application-specific values that you want to preserve. To do so, you can use one of the state management options.
Client-Based State Management Options:
View State
Hidden Form Fields
Cookies
Query Strings
Server-Based State Management Options
Application State
Session State
Database Support

29 What tags do you need to add within the asp:datagrid tags to bind columns manually?
Answer1:    Set AutoGenerateColumns Property to false on the datagrid tag
Answer2:    tag and either or tags (with appropriate attributes of course)

30 What are the disadvantages of viewstate/what are the benefits?
Answer1:   Disadvantage of viewstate is that additional data is sent to the browser. The benefits are that you do not have to manually manage refreshing the page fields after a submit, (when re-displaying the same page).
Answer2Automatic view-state management is a feature of server controls that enables them to repopulate their property values on a round trip (without you having to write any code). This feature does impact performance, however, since a server control’s view state is passed to and from the server in a hidden form field. You should be aware of when view state helps you and when it hinders your page’s performance.

31 Describe session handling in a webfarm, how does it work and what are the limits?
Set the sessionState mode in the web.config file to “StateServer”.
StateServer mode uses an out-of-process Windows NT Server to store state information.
It solves the session state loss problem in InProc mode. Allows a webfarm to store session on a central server. It provides a Single point of failure at the State Server.
Follow these simple steps:
- In a web farm, make sure you have the same in all your web servers.
- Also, make sure your objects are serializable.
- For session state to be maintained across different web servers in the web farm, the Application Path of the website in the IIS Metabase should be identical in all the web servers in the web farm.

32 How many classes can a single .NET DLL contain?
Unlimited.

33 True or False: To test a Web service you must create a windows application or Web application to consume this service?
False.
34 Which control would you use if you needed to make sure the values in two different controls matched?
Use the CompareValidator control to compare the values of 2 different controls.

35 How is a property designated as read-only?
In VB.NET:
Public ReadOnly Property PropertyName As ReturnType
Get ‘Your Property Implementation goes in here
End Get
End Property
in C#
public returntype PropertyName         {
get{     //property implementation goes here       
     }    
// Do not write the set implementation
}

36 What tags do you need to add within the asp:datagrid tags to bind columns manually?
Column tag and an ASP:databound tag.

37 Where on the Internet would you look for Web services?
UDDI repositaries like uddi.microsoft.com, IBM UDDI node, UDDI Registries in Google Directory, enthusiast sites like XMethods.net.

38 What does WSDL stand for?
Web Services Description Language

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

40 What is the transport protocol you use to call a Web service?
Answer1:
SOAP. Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet infrastructure. This in fact imposes the usage of of the HTTP, SMTP and FTP protocols based on the TCP/IP family of transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard.
Answer2:
SOAP is not the transport protocol. SOAP is the data encapsulation protocol that is used but the transport protocol is fairly unlimited. Generally HTTP is the most common transport protocol used though you could conceivanly use things like SMTP or any others. SOAP is not dependant on any single transport protocol or OS, it is a syntactical and logical definition, not a transport protocol.


41 Which method do you use to redirect the user to another page without performing a round trip to the client?
Server.transfer( )

42 How do you create a permanent cookie?
Setting the Expires property to MinValue means that the Cookie never expires.

43 Which two properties are on every validation control?
ControlToValidate & ErrorMessage properties

44 How do you turn off cookies for one page in your site?
Use the Cookie.Discard Property which Gets or sets the discard flag set by the server. When true, this property instructs the client application not to save the Cookie on the user’s hard disk when a session ends.

45 What method do you use to explicitly kill a user’s session?
The 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.
Syntax: Session.Abandon

46 What base class do all Web Forms inherit from?
System.Web.UI.Page

47 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 DataMember property which Gets or sets the specific table in the DataSource to bind to the control and the DataBind method to bind data from a source to a server control. This method is commonly used after retrieving a data set through a database query.

48 How can you provide an alternating color scheme in a Repeater control?
AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row (alternating items) in the Repeater control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.

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

50 Which method do you invoke on the DataAdapter control to load your generated dataset with data?
System.Data.Common.DataAdapter.Fill(System.Data.DataSet);
If my DataAdapter is sqlDataAdapter and my DataSet is dsUsers then it is called this way:
sqlDataAdapter.Fill(dsUsers);

51 In what order do the events of an ASPX page execute. As a developer is it important to understand these events?
Every Page object (which your .aspx page is) has nine events, most of which you will not have to worry about in your day to day dealings with ASP.NET. The three that you will deal with the most are: Page_Init, Page_Load, Page_PreRender.
By on September 21, 2010 | ASP .Net

52 Where would you use an iHTTPModule, and what are the limitations of anyapproach you might take in implementing one?
One of ASP.NET’s most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre- and post-processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.

53 Explain what a diffgram is, and a good use for one?
A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.

54 Describe the difference between inline and code behind – which is best in a loosely coupled solution?
ASP.NET supports two modes of page development: Page logic code that is written inside


No comments:

Post a Comment