Explain the Services of CLR
CLR (Common Language Runtime) is the execution engine of the .NET Framework. It manages the execution of .NET programs and provides several important services.
Main Services of CLR
try-catch-finally.Differentiate between Managed Code and Unmanaged Code
| Basis | Managed Code | Unmanaged Code |
|---|---|---|
| Execution | Runs under the control of the CLR. | Runs directly under the operating system. |
| Memory Management | Managed automatically by the Garbage Collector. | Generally handled manually by the programmer. |
| Compilation | Source code → MSIL → Native Code using JIT. | Compiled directly into native machine code. |
| Examples | C#, VB.NET | C, C++ |
| Safety | Provides type safety and CLR-managed security. | Programmer is responsible for safety and memory management. |
| Platform | Generally more portable within the .NET environment. | Generally platform-dependent. |
Differentiate between CLR and FCL
| Basis | CLR | FCL |
|---|---|---|
| Full Form | Common Language Runtime | Framework Class Library |
| Purpose | Provides the execution environment for .NET programs. | Provides pre-built, reusable classes and libraries for application development. |
| Main Function | Manages code execution, memory, security, exceptions, and JIT compilation. | Provides ready-made functionality for tasks such as I/O, collections, data handling, etc. |
| Example | JIT Compiler, Garbage Collector, Exception Manager | System, System.IO, System.Collections, System.Data |
Explain the Features of ASP.NET
ASP.NET is a server-side web development framework used to build dynamic and interactive web applications. Its important features are:
- 01Server-Side Technology — ASP.NET code runs on the server and generates HTML that is sent to the browser.
- 02Compiled — ASP.NET applications are compiled, providing better performance than interpreted scripting.
- 03Rich Server Controls — Provides ready-made controls such as TextBox, Button, GridView, etc.
- 04State Management — Supports ViewState, Session, Cookies, and Application objects to maintain data between requests.
- 05Security — Provides built-in authentication and authorization features.
- 06Database Integration — Supports database access through ADO.NET, LINQ, and Entity Framework.
- 07Easy Configuration and Debugging — Uses Web.config and provides debugging support through Visual Studio.
- 08Master Pages — Allows a common layout and consistent appearance across multiple pages.
Explain the Framework Class Library (FCL)
FCL (Framework Class Library) is a large collection of pre-built and reusable classes, methods, and libraries provided by the .NET Framework. It helps developers perform common programming tasks without writing the functionality from scratch.
Examples of FCL Classes / Libraries
Advantages
- 01Reduces repetitive coding.
- 02Provides ready-made functionality.
- 03Makes application development faster and easier.
Explain the .NET Framework and its Main Components
The .NET Framework is a software framework developed by Microsoft for developing and executing applications. It provides a common runtime environment for programs written in different .NET languages.
Main Components
The execution engine that manages program execution, memory, security, and exceptions.
A collection of pre-built, reusable classes and libraries used for application development.
Explain the Code Behind Model in ASP.NET
The Code Behind model is an ASP.NET programming model in which the user interface (UI) and programming logic are separated into two files:
Example
Default.aspx:
<asp:Button ID="btn1" runat="server"
Text="Click Me" OnClick="btn1_Click" />
<asp:Label ID="lbl1" runat="server" />
Default.aspx.cs:
protected void btn1_Click(object sender, EventArgs e)
{
lbl1.Text = "Hello!";
}
What is ViewState? Explain its Purpose in ASP.NET
ViewState is a state-management mechanism in ASP.NET used to preserve the values of controls between postbacks. It stores the state of page and control properties in a hidden field on the page.
Purpose of ViewState
- 01Maintains control values when the page is submitted and reloaded.
- 02Helps preserve the state of controls between postbacks.
- 03Allows ASP.NET pages to retain their previous values without storing them on the server.
Example
<asp:TextBox ID="txtName" runat="server" />
If the user enters a value and the page performs a postback, ViewState helps preserve the entered value.
Explain the Architecture of the .NET Framework with a Neat Diagram. Explain CLR, CTS, CLS and FCL
The .NET Framework is a software framework that provides a common environment for developing and executing applications written in different .NET languages. Its architecture allows different languages to work together using common runtime and type-system rules.
Architecture Diagram
.NET Languages
┌──────────────────────┐
│ C# │ VB.NET │ Other │
└──────────┬───────────┘
↓
┌─────────────────┐
│ CLS │
│ Common Language │
│ Specification │
└────────┬─────────┘
↓
┌─────────────────┐
│ CTS │
│ Common Type │
│ System │
└────────┬─────────┘
↓
┌─────────────────┐
│ FCL │
│ Framework Class │
│ Library │
└────────┬─────────┘
↓
┌─────────────────┐
│ CLR │
│ Common Language │
│ Runtime │
└────────┬─────────┘
↓
Operating System
CLR is the execution engine of the .NET Framework. It manages the execution of .NET programs and provides services such as:
JIT compilation — converts CIL/MSIL into native machine code. Garbage Collection — automatically manages unused memory. Security — checks code safety. Exception Handling — handles runtime errors. Memory Management — allocates and manages memory.
CTS defines a common set of data types and rules used by all .NET languages. It provides type safety and allows different .NET languages to work together.
For example, int in C# and Integer in VB.NET both map to System.Int32.
CLS defines a set of rules that .NET languages must follow to ensure cross-language compatibility.
It allows code written in one .NET language to be safely used by another .NET language. CLS is a subset of CTS.
FCL is a large collection of pre-built and reusable classes and libraries provided by the .NET Framework. It saves developers from writing common functionality from scratch.
Examples include System, System.IO, System.Collections, and System.Data.
Compilation Flow
Source Code
↓
Language Compiler
↓
MSIL / CIL
↓
CLR (JIT Compiler)
↓
Native Machine Code
↓
Execution
Explain the ASP.NET Page Life Cycle with a Neat Diagram
The ASP.NET Page Life Cycle is the sequence of stages through which an ASP.NET page passes from the time it is requested by the browser until the response is sent back. Each stage provides specific events that can be used to initialize controls, handle events, save state, and generate the final HTML.
Page Life Cycle Diagram
Page Request
↓
PreInit
↓
Init
↓
InitComplete
↓
LoadViewState
↓
LoadPostData
↓
Load
↓
PostBack Events
↓
LoadComplete
↓
PreRender
↓
SaveStateComplete
↓
Render
↓
Unload
Main Stages
The earliest stage of the page life cycle. It is used for tasks such as dynamically changing the Master Page or Theme.
Controls are initialized and their initial settings are prepared.
ASP.NET restores the previously stored ViewState of the page and its controls.
Values submitted by the user are loaded into the appropriate controls.
The page and its controls are loaded. Page_Load is commonly used to load data and set control properties. IsPostBack can be checked to determine whether the page is being loaded for the first time.
Events caused by user actions are processed, such as Button.Click, TextBox.TextChanged, and DropDownList.SelectedIndexChanged.
All controls have completed their loading process.
This is the last opportunity to modify the page or controls before the HTML is generated.
The ViewState is saved to the hidden field.
ASP.NET generates the final HTML and sends it to the response stream.
The page is removed from memory and cleanup operations such as closing database connections and releasing file handles can be performed.
Explain PostBack with its Advantages and Disadvantages
PostBack is the process in which an ASP.NET web page submits data back to the server for processing. The request is generally sent back to the same page (same URL). It commonly occurs when the user performs an action such as clicking a Button or changing a control value.
Working of PostBack
User opens ASP.NET Page
↓
Page displayed
↓
User performs action
(e.g. Button Click)
↓
HTTP POST
↓
Same page sent to Server
↓
Server processes event
↓
Response sent to Browser
Example
<asp:Button ID="btnSubmit"
runat="server"
Text="Submit"
OnClick="btnSubmit_Click" />
<asp:Label ID="Label1" runat="server" />
Code-behind:
protected void btnSubmit_Click(object sender, EventArgs e)
{
Label1.Text = "Button clicked!";
}
When the button is clicked, the page is submitted to the server and the btnSubmit_Click event is executed.
IsPostBack
ASP.NET provides the IsPostBack property to determine whether the page is being loaded for the first time or because of a postback:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = "Welcome!";
}
}
IsPostBack = false → First time the page loads. IsPostBack = true → Page has been submitted back to the server.
- 01Server-side processing — Allows ASP.NET server events and logic to be executed.
- 02Easy event handling — Controls such as Button, TextBox and DropDownList can trigger server-side events.
- 03State preservation — ViewState can preserve control values between postbacks.
- 04Database interaction — Server-side code can process submitted data and interact with databases.
- 01Page reload — A postback normally requires a round trip between browser and server.
- 02Network overhead — Data is sent to the server and a response is returned.
- 03Slower user experience — Frequent postbacks can make an application feel less responsive.
- 04Server load — Frequent postbacks increase processing requirements on the server.
Explain the Common Type System (CTS) and Common Language Specification (CLS)
CTS (Common Type System) defines how data types are declared, used, and managed by the .NET runtime. It provides a common set of data types and rules that are understood by all .NET-supported languages.
For example, C# int and VB.NET Integer both represent the .NET type System.Int32.
Features of CTS: provides a common type system for all .NET languages; ensures type safety during program execution; allows different .NET languages to share and exchange data; defines types such as value types and reference types.
CLS (Common Language Specification) is a set of rules that .NET languages follow to ensure language interoperability.
It defines a common set of features that can be safely used across different .NET languages. Any language that follows CLS rules can interoperate with other CLS-compliant languages.
Features of CLS: provides language interoperability; allows code written in one .NET language to be used by another .NET language; defines a common set of rules that languages should follow; CLS is a subset of CTS.
Difference between CTS and CLS
| CTS | CLS |
|---|---|
| Defines the types and rules used by the .NET runtime. | Defines rules for language interoperability. |
| Ensures type safety. | Ensures cross-language compatibility. |
| Contains a broader set of types and features. | Contains a smaller, common subset of CTS. |