Sunday 22 September 2013

DotNet Interview Question & Answers

1. Please briefly explain ASP.NET Page life Cycle?

ASP.NET page passes through a series of steps during its life cycle. Following is the high-level explanation of life cycle stages/steps.
Initialization: Controls raise their Init event in this stage.Objects and variables are initializes for complete lifecyle of request.
LoadViewState: is a post back stage and loads the view state for the controls that enabled its view state property.
LoadPostBackData: is also a post back stage and loads the data posted for the controls and update them.
Load: In this stage page as well as all the controls raise their Load event. Till this stage all the controls are initialized and loaded. In most of the cases, we are coding this event handler.
RaisePostBackEvent: is again a postback stage. For example, it's raise against a button click event. We can easily put our code here to perform certain actions.
SaveViewState: Finally, controls state is saved in this stage before Rendering HTML.
Render: This is the stage where HTML is generated for the page.
Dispose: Lastly, all objects associated with the request are cleaned up.
For very detailed explanation of Page Life Cycle is explained here.

2. What is the difference between custom controls and user controls?

Custom controls are basically compiled code i.e. DLLs. These can be easily added to toolbox, so it can be easily used across multiple projects using drag and drop approach. These controls are comparatively hard to create.
But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly couple with respect to User Interface and code. In order to use across multiple projects, we need to copy and paste to the other project as well.

3. What is the concept of view state in ASP.NET?

As in earlier question, we understood the concept of postback. So, in order to maintain the state between postbacks, ASP.NET provides a mechanism called view state. Hidden form fields are used to store the state of objects on client side and returned back to server in subsequent request (as postback occurs).

3. Differentiate between:

a.)Client-side and server-side validations in Web pages.

- Client-side validations happends at the client's side with the help of JavaScript and VBScript. This happens before the Web page is sent to the server.
- Server-side validations occurs place at the server side.

b.)Authentication and authorization.

  •  Authentication is the process of verifyng the identity of a user using some credentials like username and password while authorization determines the parts of the system to which a particular identity has access. 
  •  Authentication is required before authorization. 

For e.g. If an employee authenticates himself with his credentials on a system, authorization will determine if he has the control over just publishing the content or also editing it.

4.a.) What does the .WebPart file do?

It explains the settings of a Web Parts control that can be included to a specified zone on a Web page.

b.) How would you enable impersonation in the web.config file?

In order to enable the impersonation in the web.confing file, take the following steps: 
  •  Include the <identity> element in the web.config file. 
  •  Set the impersonate attribute to true as shown below: 
  •  <identity impersonate = "true" />

5. What are the different kinds of assemblies?
There can be two types of assemblies.

i.) Static assemblies -
  •  They are stored on disk in portable executable files. 
  •  It includes .NET Framework types like interfaces and classes, resources for the assembly (bitmaps, JPEG files, resource files etc.).

ii.) Dynamic assemblies -
  •  They are not saved on disk before execution rather they run directly from memory. 
  • They can be saved to disk after they have been executed.
6. Differentiate between Structure and Class.
  •  Structures are value type while Classes are reference type.
  •  Structures can not have constructor or destructors while Classes can have them. 
  •  Structures do not support Inheritance while Classes do support Inheritance.

7. What are the various types of Authentication?
There are 3 types of Authentication namely Windows, Forms and Passport Authentication.
  •  Windows authentication - It uses the security features integrated in Windows NT and Windows XP OS to authenticate and authorize Web application users.
  •  Forms authentication - It allows you to create your own list of users and validate their identity when they visit the Web site.
  • Passport authentication - It uses the Microsoft centralized authentication provider to identify users. Passport allows users to use a single identity across multiple Web applications. Passport SDK needs to be installed to use Passport authentication in your Web application.
8. Explain Server-side scripting and Client-side scripting.
  • Server side scripting - All the script are executed by the server and interpreted as needed. 
  • Client side scripting means that the script will be executed immediately in the browser such as form field validation, email validation, etc. It is usaullay carrried out in VBScript or JavaScript.
9. a.) What is garbage collection?
It is a system where a run-time component takes responsibility for managing the lifetime of objects and the heap memory that they occupy.

b.) Explain serialization and deserialization.

  •  Serialization is the process of converting an object into a stream of bytes.
  •  Deserialization is the process of creating an object from a stream of bytes. 
Both these processes are usually used to transport objects.

10. What are the different types of Validation controls in ASP.NET?
In order to validate user input, ASP.NET provides validation server controls. All validation controls inherits from BaseValidator class which contains the common validation properties and methods like ControlToValidate,EnabledIsValidEnableClientScriptValidationGroup,Validate() etc.
ASP.NET provides a range of validation controls:

  • RequiredFieldValidator validates compulsory/required input.
  • RangeValidator validates the range. Validates that input falls between the given range values.
  • CompareValidator validates or compares the input of a control with another control value or with a fixed value.
  • RegularExpressionValidator validates input value against a defined regular expression pattern.
  • CustomValidator allows to customize the validation logic with respect to our application logic.
  • ValidationSummary displays all errors on page collectively.

    11. What is the difference between custom controls and user controls?

    Custom controls are basically compiled code i.e. DLLs. These can be easily added to toolbox, so it can be easily used across multiple projects using drag and drop approach. These controls are comparatively hard to create.
    But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly couple with respect to User Interface and code. In order to use across multiple projects, we need to copy and paste to the other project as well.

    12. Please briefly explain the usage of Global.asax?
    Global.asax is basically ASP.NET Application file. It’s a place to write code for Application-level events such as Application start, Application end, Session start and end, Application error etc. raised by ASP.NET or by HTTP Modules.
    There is a good list of events that are fired but following are few of the important events in Global.asax:
    • Application_Init occurs in case of application initialization for the very first time.
    • Application_Start fires on application start.
    • Session_Start fires when a new user session starts
    • Application_Error occurs in case of an unhandled exception generated from application.
    • Session_End fires when user session ends.
    • Application_End fires when application ends or time out.
    13. Difference between Abstract and Interface

    Abstract Class:
    • Abstract class provides a set of rules to implement next class
    • Rules will be provided through abstract methods
    • Abstract method does not contain any definition
    • While inheriting abstract class all abstract methods must be override
    • If a class contains at least one abstract method then it must be declared as an “Abstract Class”
    • Abstract classes cannot be instantiated (i.e. we cannot create objects), but a reference can be created
    • Reference depends on child class object’s memory
    • Abstract classes are also called as “Partial abstract classes”
    • Partial abstract class may contain functions with body and functions without body
    • If a class contains all functions without body then it is called as “Fully Abstract Class” (Interface)
    Interface:
    If a class contains all abstract methods then that class is known as “Interface”

    • Interfaces support like multiple inheritance
    • In interface all methods r public abstract by default
    • Interfaces r implementable
    • Interfaces can be instantiated, but a reference cannot be created

    14. What is boxing and unboxing concepts in .net? 

    •  Boxing is a process of converting value type into reference type
    •  Unboxing is a process of converting reference type to value type.

    15. What are the different levels of State management in ASP.NET?

    State management is the process by which you maintain state and page information over multiple requests for the same or different pages.

    There are 2 types State Management: 

    1. Client – Side State Management 
    This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator (url), or a cookie. The techniques available to store the state information at the client end are listed down below: 

    a. View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state. 

    b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state. 

    c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed. 

    d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site. 

    e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL. 

    2. Server – Side State Management 
    a. Application State - Application State information is available to all pages, regardless of which user requests a page. 

    b. Session State – Session State information is available to all pages opened by a user during a single visit. 

    Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.



    16. What is the location of Global Assembly Cache on the system?


     c:\Windows\assembly



     17. What is the serialization?

     Serialization is a process of converting object into a stream of bites.

    18. What is synchronization?

        The mechanism needed to block one thread access to the data. If the data is being accessed by another thread.
    Synchronization can be accessed by using system.monitor class
    A monitor class methods are enter, exit, pulse for this lock statement is also used
    Suppose if we need to synchronize some data at that time we need to place that data in this block
    Lock
    {
    }
    Whatever the data has been placed into the lock block that data has been blocked

    19. What are the thread priority levels?

       Thread priority levels are five types
             0 - Zero level
             1 - Below Normal
             2 - Normal
             3 - Above Normal
             4 - Highest
    By Default priority level is 2


           20. What is Difference between NameSpace and Assembly?
    Following are the differences between namespace and assembly:

    • Assembly is physical grouping of logical units, Namespace, logically groups classes.
    • Namespace can span multiple assembly.


      22. What is Reflection?
        Reflection is used to dynamically load a class , create object and invoke methods at runtime. It can also be used read its own meta data to find assemblies, modules and type information at runtime.

        23. What is delegate?

        A delegate acts like a strongly type function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods. It is type safe since it holds reference of only those methods that match its signature. Unlike other classes, the delegate class has a signature. Delegates are used to implement event programming model in .NET application. Delegates enable the methods that listen for an event, to be abstract.

        24. Explain Exception handling in .Net.


        Exceptions or errors are unusual occurrences that happen within the logic of an application. The CLR has provided structured way to deal with exceptions using Try/Catch block. ASP.NET supports some facilities to handling exceptions using events suck as Page_Error and Application_Error.

        25. What’s difference between System exceptions and Application exceptions?
        System exceptions are common exceptions thrown by the CLR of .Net Framework. Application exceptions can be user defined exceptions thrown by the application.


        No comments:

        Post a Comment