1. What is ASP.NET?
Answer
ASP.NET is a server-side web application framework developed by Microsoft. It is built on the Common Language Runtime (CLR) and allows developers to build dynamic web applications.
Reference
2. Explain the Life Cycle of an ASP.NET page.
Answer
The ASP.NET page life cycle includes various stages such as Initialization, Loading, Rendering, and Unloading.
Code Snippet
protected void Page_Load(object sender, EventArgs e) {
// Your code here
}
Explanation
The Page_Load
method is invoked during the Load stage of the page life cycle.
Reference
3. What is ViewState?
Answer
ViewState is a mechanism in ASP.NET to persist data across postbacks.
Code Snippet
ViewState["UserName"] = "JohnDoe";
Explanation
The above code snippet stores the username in ViewState for later retrieval.
Reference
4. Explain Master Pages.
Answer
Master Pages in ASP.NET provide a template for creating consistent layouts across web pages.
Code Snippet
<%@ Master Language="C#" %>
<!DOCTYPE html>
<html>
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</html>
Explanation
The ContentPlaceHolder
defines where the content pages will inject their specific content.
Reference
5. What is Web.config?
Answer
Web.config
is an XML-based configuration file for managing various settings of an ASP.NET application.
Code Snippet
<configuration>
<appSettings>
<add key="Setting1" value="Value1"/>
</appSettings>
</configuration>
Explanation
The code snippet above adds a custom application setting named โSetting1โ with a value of โValue1โ.
Reference
6. What are HTTP Handlers?
Answer
HTTP Handlers are components in ASP.NET responsible for handling specific types of requests.
Reference
7. What is the difference between Web Forms and MVC in ASP.NET?
Answer
Web Forms is an event-driven model, whereas MVC (Model-View-Controller) is a pattern separating an application into three components: Model, View, and Controller.
Reference
8. What is Razor Syntax?
Answer
Razor syntax is a programming syntax for embedding server-based code into web pages in ASP.NET.
Code Snippet
@{
var name = "John";
}
Hello, @name!
Explanation
The code declares a variable name
and uses it in the HTML markup.
Reference
9. What is Entity Framework?
Answer
Entity Framework is an Object-Relational Mapping (ORM) framework for .NET applications to interact with a database.
Reference
10. What is Caching in ASP.NET?
Answer
Caching is a technique to store frequently accessed data in a temporary storage area to improve performance.
Code Snippet
Cache["key"] = "value";
Explanation
The above code snippet adds a key-value pair to the cache.
Reference
11. What are ASP.NET Server Controls?
Answer
ASP.NET Server Controls are components that execute on the server and encapsulate the HTML interface for rendering.
Code Snippet
<asp:Label ID="lblMessage" runat="server" Text="Hello, World!"></asp:Label>
Explanation
The asp:Label
control renders as an HTML label with the text โHello, World!โ
Reference
12. How do you manage state in ASP.NET?
Answer
State in ASP.NET can be managed using techniques like Cookies, Query Strings, Hidden Fields, ViewState, and Session.
Reference
13. What is AJAX in ASP.NET?
Answer
AJAX (Asynchronous JavaScript and XML) in ASP.NET is used to create asynchronous web applications.
Reference
14. What are User Controls?
Answer
User Controls (.ascx) are reusable components that encapsulate UI and logic, which can be used across multiple pages.
Code Snippet
<%@ Control Language="C#" %>
<asp:Label ID="lblInfo" runat="server"></asp:Label>
Explanation
This User Control contains an ASP.NET Label control for displaying information.
Reference
15. What is LINQ?
Answer
LINQ (Language-Integrated Query) is a query syntax in .NET for querying different data sources directly from C#.
Code Snippet
var result = from num in numbers
where num > 5
select num;
Explanation
The code filters the numbers greater than 5 from the numbers
collection.
Reference
16. What are the different types of Authentication in ASP.NET?
Answer
ASP.NET supports several types of authentication such as Forms, Windows, and OAuth.
Reference
17. Explain the Global.asax file.
Answer
Global.asax
is used to handle application-level and session-level events in an ASP.NET application.
Reference
18. What is the difference between Response.Redirect
and Server.Transfer
?
Answer
Response.Redirect
navigates to a different URL and performs a trip back to the client. Server.Transfer
transfers execution to another ASP.NET page on the server.
Reference
19. What is Bundling and Minification in ASP.NET?
Answer
Bundling and Minification are techniques for improving request load time by reducing the number of requests to the server and reducing the size of the requested assets like CSS, JavaScript.
Reference
20. How can you implement error handling in ASP.NET?
Answer
Error handling can be done using Try...Catch
blocks, custom error pages, and using Global.asax
for application-level errors.
Reference
21. What is Cross-Site Scripting (XSS) and how do you prevent it?
Answer
Cross-Site Scripting (XSS) is an attack where malicious scripts are injected into websites viewed by other users. To prevent it, use input validation and output encoding.
Reference
22. What are the different Session State Modes in ASP.NET?
Answer
ASP.NET supports various session state modes such as InProc, StateServer, and SQLServer.
Reference
23. What is ViewState and how does it work?
Answer
ViewState is a mechanism to maintain the state of controls during page postbacks in ASP.NET.
Reference
24. What is the Page Life Cycle in ASP.NET?
Answer
The Page Life Cycle in ASP.NET includes events like Initialization, Load, PostBack event handling, and Rendering.
Reference
25. What is Dependency Injection in ASP.NET Core?
Answer
Dependency Injection is a design pattern to achieve Inversion of Control between classes and their dependencies.
Reference
26. What are ASP.NET MVC Filters?
Answer
ASP.NET MVC Filters are attributes that can be applied to controllers or actions to inject logic at different stages of request processing.
Reference
27. What is the purpose of web.config
?
Answer
web.config
is an XML file for configuration settings of an ASP.NET application.
Reference
28. How do you create a RESTful API using ASP.NET?
Answer
RESTful APIs in ASP.NET can be created using the Web API framework, which supports HTTP methods like GET, POST, PUT, and DELETE.
Reference
29. What is Data Binding in ASP.NET?
Answer
Data Binding refers to the linking of a data source to the presentation layer.
Reference
30. How do you secure an ASP.NET application?
Answer
Security in ASP.NET can be implemented using authentication, authorization, secure communication channels like HTTPS, and data encryption.
Reference
31. What is the Role of Global.asax?
Answer
Global.asax
is used for application-level events and settings. It handles events such as Application_Start, Session_Start, and Application_Error.
Reference
32. What is Entity Framework?
Answer
Entity Framework is an ORM framework for .NET applications, allowing developers to work with relational data as objects.
Reference
33. How to perform file uploads in ASP.NET?
Answer
File uploads can be performed using the FileUpload
control which provides the SaveAs
method to save uploaded files.
Reference
34. What are ASP.NET Identity and Membership?
Answer
ASP.NET Identity is the identity system that replaced the older Membership system for identity management.
Reference
35. What is Razor in ASP.NET?
Answer
Razor is a templating engine used in ASP.NET Core for generating dynamic HTML markup from C# code.
Reference
36. How does the UpdatePanel
control work?
Answer
UpdatePanel
controls enable you to refresh only a part of a page instead of the whole page during a postback.
Reference
37. What is LINQ in .NET?
Answer
LINQ (Language-Integrated Query) allows you to write declarative queries directly in C# or VB.NET, often used with Entity Framework.
Reference
38. How to implement Pagination in ASP.NET?
Answer
Pagination can be implemented using controls like PagedDataSource
, GridView
, or manually through code.
Reference
39. What are HttpHandlers and HttpModules?
Answer
HttpHandlers
handle specific request types while HttpModules
provide a way to interact with the request pipeline.
Reference
40. What is Caching in ASP.NET?
Answer
Caching improves performance by storing copies of frequently accessed data and serving it from the cache rather than regenerating it.
Reference
41. What is MVC in ASP.NET?
Answer
MVC (Model-View-Controller) is an architectural pattern that separates the application into three main components: Model, View, and Controller.
Reference
42. How to implement Error Handling?
Answer
Error handling can be implemented using try-catch
blocks, custom error pages, and the Application_Error
event in Global.asax.
Reference
43. What is SignalR?
Answer
SignalR is a library that provides real-time web functionality to ASP.NET applications.
Reference
44. What are Filters in ASP.NET?
Answer
Filters are custom classes that provide a way for running code before or after specific stages in the request processing pipeline.
Reference
45. What is Dependency Injection?
Answer
Dependency Injection is a design pattern that allows the inversion of control for better code maintainability.
Reference
46. What are Bundles in ASP.NET?
Answer
Bundles are a way to combine and minimize multiple CSS or JavaScript files to improve performance.
Reference
47. What is Web API?
Answer
Web API is a framework for building HTTP services that can be accessed from any client, including browsers and mobile devices.
Reference
48. Explain Session State.
Answer
Session State allows storing user-specific data between HTTP requests.
Reference
49. What is ADO.NET?
Answer
ADO.NET is a set of classes that provide data access services for .NET applications, supporting connection to various data sources.
Reference
50. How to secure an ASP.NET application?
Answer
Security can be implemented through authentication, authorization, and by using secure communication channels like HTTPS.
Reference
51. What is Razor View in ASP.NET?
Answer
Razor is a markup syntax used for embedding server-based code into web pages.
Reference
52. Explain ViewBag in ASP.NET MVC.
Answer
ViewBag is a dynamic object that allows you to share values from the Controller to the View.
Reference
53. What are ActionResults in MVC?
Answer
ActionResult
is a return type of a controller method in MVC, used to render the correct view or redirect the user.
Reference
54. What is Entity Framework?
Answer
Entity Framework (EF) is an ORM framework for interacting with databases in a .NET application.
Reference
55. How do you perform unit testing in ASP.NET?
Answer
Unit testing in ASP.NET can be performed using frameworks like MSTest, NUnit, or xUnit.
Reference
56. Explain the Page Life Cycle in ASP.NET.
Answer
The Page Life Cycle in ASP.NET includes stages like initialization, loading, rendering, and unloading.
Reference
57. What are HttpHandlers?
Answer
HttpHandlers
are low-level request handlers in ASP.NET, invoked to process incoming HTTP requests.
Reference
58. What is OWIN?
Answer
OWIN (Open Web Interface for .NET) is a specification for building web server and client applications to enable modular architecture.
Reference
59. What is ViewState?
Answer
ViewState
is a technique used in Web Forms to maintain the state of controls across postbacks.
Reference
60. How to implement Caching in ASP.NET?
Answer
Caching can be implemented using OutputCaching
for views or MemoryCache
for data storage.
Reference
61. What is TempData in ASP.NET?
Answer
TempData
is a dictionary-like object used to temporarily store data between two consecutive requests from the same user.
Reference
62. How to handle exceptions in ASP.NET?
Answer
You can handle exceptions using built-in features like try-catch
blocks, custom error pages, and logging frameworks like NLog or Serilog.
Reference
63. Explain SignalR in ASP.NET
Answer
SignalR is a library that enables real-time communication between the server and connected clients.
Reference
64. What is Dependency Injection in ASP.NET?
Answer
Dependency Injection (DI) is a design pattern used for achieving Inversion of Control between classes and their dependencies.
Reference
65. What is Bundling and Minification?
Answer
Bundling combines multiple files into a single file. Minification removes unnecessary characters from code to reduce its size.
Reference
66. What are Layouts in MVC?
Answer
Layouts are shared templates in MVC that provide a consistent look and feel across multiple views.
Reference
67. Explain AJAX in ASP.NET.
Answer
AJAX (Asynchronous JavaScript and XML) is used for creating interactive web applications by making asynchronous requests to the server.
Reference
68. How does HTTPS work in ASP.NET?
Answer
HTTPS is implemented using SSL/TLS protocols and requires a valid certificate. ASP.NET provides attributes to enforce HTTPS.
Reference
69. What is Cross-Origin Resource Sharing (CORS)?
Answer
CORS is a mechanism that allows or restricts web resources on a domain to interact with resources on another domain.
Reference
70. Explain Areas in ASP.NET MVC.
Answer
Areas are used to partition a large application into smaller functional groupings, each with its own set of controllers, views, and models.
Reference
71. What is Attribute Routing in ASP.NET MVC?
Answer
Attribute routing uses attributes to define routes directly on actions and controllers in ASP.NET MVC.
Reference
72. What is Model Validation in ASP.NET?
Answer
Model Validation ensures that incoming data conforms to application rules using data annotations or custom validation logic.
Reference
73. Explain Razor Views in ASP.NET.
Answer
Razor Views are templates in ASP.NET that have C# code logic to generate dynamic HTML content.
Reference
74. What is Web API in ASP.NET?
Answer
Web API is a framework for creating HTTP services that can be accessed from any client, including browsers and mobile devices.
Reference
75. How to Enable CORS in ASP.NET Core?
Answer
CORS in ASP.NET Core can be enabled by adding the CORS middleware and configuring CORS policy in the Startup.cs
file.
Reference
76. What is Caching in ASP.NET?
Answer
Caching is the process of storing frequently accessed data in a โcacheโ memory to reduce load time and server latency.
Reference
77. What is Tag Helper in ASP.NET Core?
Answer
Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.
Reference
78. What is a View Component in ASP.NET Core?
Answer
View Components are similar to partial views, but they come with a code-behind class where you can put your logic.
Reference
79. What is OWIN Middleware in ASP.NET?
Answer
OWIN (Open Web Interface for .NET) Middleware serves as the bridge between web servers and web applications for routing requests and responses.
Reference
80. What is Data Annotations in ASP.NET?
Answer
Data Annotations are attributes that can be applied to a model class to configure its behavior, validate user input, and define relations.
Reference
81. How to Perform Authentication in ASP.NET Core?
Answer
Authentication in ASP.NET Core is usually done using Identity, a library that supports user interface and backend for login functionality.
Reference
82. What is CSRF Attack and How to Prevent It in ASP.NET?
Answer
CSRF (Cross-Site Request Forgery) is an attack where unauthorized commands are transmitted from a trusted user. ASP.NET Core prevents CSRF using anti-forgery tokens.
Reference
83. Explain Role-Based Authorization in ASP.NET.
Answer
Role-Based Authorization controls access to resources based on the roles assigned to a user. Itโs implemented using the Authorize
attribute with roles specified.
Reference
84. What is Endpoint Routing?
Answer
Endpoint Routing in ASP.NET Core allows more control over the routing behavior and serves as a middleware to handle requests.
Reference
85. What is Dependency Injection in ASP.NET Core?
Answer
Dependency Injection (DI) is a technique to achieve Inversion of Control between classes and their dependencies, facilitated natively in ASP.NET Core.
Reference
86. Explain Areas in ASP.NET Core MVC.
Answer
Areas provide a way to partition a large ASP.NET Core MVC Web app into smaller functional groupings with their own controllers and views.
Reference
87. What is the Difference Between TempData, ViewData, and ViewBag?
Answer
- TempData: Retains data between actions, limited to a single session.
- ViewData: Transfers data from controller to view, not strongly-typed.
- ViewBag: A dynamic wrapper around ViewData.
Reference
88. How Do You Enable Session State in ASP.NET Core?
Answer
Session state in ASP.NET Core is enabled by using middleware via the AddSession
method in Startup.cs
.
Reference
89. What is Bundling and Minification in ASP.NET?
Answer
Bundling and Minification are techniques to improve request load time by combining multiple files into a single bundle and reducing its size.
Reference
90. How to Secure Connection Strings in ASP.NET Core?
Answer
Sensitive data like connection strings can be secured in ASP.NET Core using Secret Manager, environment variables, or Azure Key Vault.
Reference
91. What is Razor Pages in ASP.NET Core?
Answer
Razor Pages is a feature in ASP.NET Core that provides a simpler way to organize code within the application. It makes coding page-focused scenarios easier.
Reference
92. How Do You Use Tag Helpers in ASP.NET Core?
Answer
Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files. They are applied using HTML-like attributes.
Reference
93. Explain JSON Web Tokens (JWT) in ASP.NET Core.
Answer
JSON Web Tokens (JWT) are used to securely transmit information between parties as a JSON object. ASP.NET Core can use JWT for authentication.
Reference
94. How to Use Caching in ASP.NET Core?
Answer
Caching can be implemented in ASP.NET Core using various techniques like Response Caching, Distributed Caching, and Memory Caching to improve performance.
Reference
95. What is Middleware in ASP.NET Core?
Answer
Middleware components handle requests and responses, forming a software pipeline between the server and the application.
Reference
96. How to Enable CORS in ASP.NET Core?
Answer
Cross-Origin Resource Sharing (CORS) can be enabled in ASP.NET Core by adding the CORS middleware to the applicationโs request pipeline.
Reference
97. Explain the use of appsettings.json in ASP.NET Core.
Answer
The appsettings.json
file is used for storing application-wide configurations that can be read at runtime.
Reference
98. How to Configure Logging in ASP.NET Core?
Answer
ASP.NET Core includes built-in logging providers that can log to various outputs. Logging can be configured in the Startup.cs
file.
Reference
99. What is the Use of wwwroot Folder in ASP.NET Core?
Answer
The wwwroot
folder is the web root directory of the application and contains static assets like CSS, JS, and images.
Reference
100. How to Handle Errors in ASP.NET Core?
Answer
Error handling in ASP.NET Core is performed using custom middleware, exception filters, or the UseExceptionHandler
method to catch and handle errors.