Uploaded by Akshay Kumar

ASP.NET Core Interview Q&A

advertisement
ASP.NET Core Interview Q&A
Agenda
• MVC Pattern Q&A
• ASP.NET Core Q&A
• Model and Views Q&A
• Controller and Actions Q&A
• View Engine and Razor Q&A
• Routing Q&A
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
MVC Pattern
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is MVC?
• MVC stands for Model-View-Controller.
• An architectural pattern which separates an
application into three main logical components:
model, view, and controller.
• Supports separation of concerns, since model
describe the data, view represent UI and controller
manage the presentation logic.
• Today, this pattern is used by many popular
frameworks like as ASP.NET MVC, ASP.NET Core,
Ruby on Rails, Spring Framework and Cake Php etc.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q2. How MVC pattern arrange an application?
Data
Object
Model
Logic
Class
Controller
UI
DOM
View
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q3. How MVC Pattern Works?
Model
View
Controller
Eg. www.domain.com/Product/Edit/1
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q3. How MVC Pattern Works?
Model
View
Eg. www.domain.com/Product/Edit/1
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Controller
Q3. How MVC Pattern Works?
Model
Changes
Presentation
Interaction
View
Notification
Notification
Presentation
Controller
Eg. www.domain.com/Product/Edit/1
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Interaction
Q4. What is the difference between Layer and Tier?
• Layer is logical separation of code.
• Tier is a physical separation of code. In fact, tier is a machine, where the
code/process runs.
DAL
DAL
(Class Library)
(WCF: Hosted App)
BAL
BAL
(Class Library)
(WebAPI: Hosted App)
PL
PL
(MVC5: Hosted App)
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
(MVC5: Hosted App)
Q5. What is the Difference between MVC and 3-Tier?
DAL
Model
BAL
View
PL
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Controller
Q5. What is the Difference between MVC and 3-Tier?
Model
View
Controller
Presentation Tier
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q6. What is the difference between Design Patterns and Architectural patterns?
• Design Patterns are applied at low-level i.e. code level.
• Design patterns example are GOF Design Patterns.
• Architectural Patterns are applied at highly-level i.e. component level.
• Architectural patterns example are MVC, MVP, SOA, 3-Tier etc.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
Introduction to ASP.NET Core
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is ASP.NET Core?
• An open-source, cross-platform and unified
framework for building Web UI and Web
APIs.
• Runs on .NET Core or on the full .NET
Framework (till ASP.NET Core 2.2).
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q2. What are ASP.NET Core Features?
• Cross-platform and Containers Support
• High performance
• Unified MVC & Web API frameworks
• Built-in dependency injection support
• New light-weight and modular HTTP request pipeline
• Ships entirely as NuGet packages
• Built-In support for SPA with client-side frameworks like Angular, React, Vue
• Serve 2300% more requests per second as compared to ASP.NET 4.6
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q3. Explain ASP.NET Core Architecture?
.NET Framework 4.6+
.NET Core 2.2
Runtime
Components
Compilers
NuGet packages
Next gen JIT (RyuJIT)
SIMD
Languages innovation
.NET Compiler Platform
.NET Core Libraries
.NET Framework 4.6 Libraries
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
ASP.NET Core 3.x/5.x Architecture
.NET Framework 4.6+
.NET Core 3.x/5.x
Runtime
Components
Compilers
NuGet packages
Next gen JIT (RyuJIT)
SIMD
Languages innovation
.NET Compiler Platform
.NET Core Libraries
.NET Framework 4.6 Libraries
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q4. How ASP.NET Core Request Processing is different from ASP.NET?
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q5. Compare ASP.NET MVC5 with ASP.NET Core?
• Html Helpers
• Tag Helpers and Html Helpers
• Follows WebForms & Razor Syntaxes
• Follows only Razor Syntax
• Partial Views: Static, Dynamic
• Partial Views & View Components
• Type: Web Application
• Type : Console Application
• Global.asax and Web.config
• startup.cs/program.cs and appsettings.json
• Modules and Handlers
• Middleware
• Hosted on IIS
• Cross-platform Kestrel web server
• Runs only with Windows
• Runs with Mac, Linux & Windows
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
Model and Views
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is Model?
Models are domain objects in our application which are used to represent
real world entities/objects.
Data Model
Business Model
Service Model
Presentation Model
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q2. What is View?
• A view is used to define the UI for your web page. It also display the data
received from the controller as a result.
• Views are stored in the Views folder and mapped to the controller’s actions.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q3. What are different Types of Views?
Standard View
Strongly Typed View
Partial View
Layout
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
Controller and Actions
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is Controller?
• A controller is a class which is used to define
presentation logic.
• By default, controllers are stored in the Controllers
folder and have Controller as suffix.
• Responds to HTTP requests with the help of actions.
• Process the received input from user, prepare the
results and send back to user.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q2. What is an action method and a Regular Method?
• An action is a method which responds to user action/activity.
• Any method in a controller which has public access modifier acts as an
action method.
Action Methods
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Regular Methods
Q3. What are the different types of Action Results?
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
View Engine and Razor
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is View Engine?
• A View Engine is an ASP.NET Core MVC subsystem which is responsible for
converting the server-side template into HTML markup and rendering it to
the browser.
• Has its own markup syntax to define server-side template where, you can
mix C# and HTML together.
• ASP.NET Core supports only Razor View Engine.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q2. What is Razor?
• A markup syntax to create dynamic web pages.
• Introduced with ASP.NET MVC 3.
• Embed with .NET languages C# and VB.
• Easily integrate with HTML Markup.
@for(int i = 1; i <= 20; i++)
{
<p>Line @i</p>
}
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q&A:
Routing
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q1. What is Routing?
• A pattern matching system that monitor the incoming request and figure
out what to do with that request
• Typically, a way to serve user request
Request
Routing
Controller
Response
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
View
Model
Q2. How Routing Works?
Route1
Url Pattern
Handler
Route2
Url Pattern
Hander
Route3
Url Pattern
Handler
Route Table
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q3. What are the different types of Routing?
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q4. How Convention based Routing works?
ASP.NET Core 1.x to 2.x
ASP.NET Core 3.x and above
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q5. How to define Attribute Routing?
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q6. What are route constraints?
• Route constraints are used to put some validation around the defined
route parameters.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q7. When to use Attribute Routing?
• Attribute routing is helpful to have more control over the Url generation
patterns. Specially to support certain URI patterns that are common in
RESTful APIs.
• For example, resources often contain child resources like Clients have
ordered, movies have actors, books have authors and so on. Route sample:
/clients/1/orders
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q8. How Routing is different from URL Rewriting?
• URL rewriting map new URL to the old URL.
Original URL: www.domain.com/product.aspx?id=1&catid=2
URL Rewriting: www.domain.com/product/1/2
• Routing map a URL to a route and a route is logically mapped to
a physical file with the help of controller and action
• Routing never rewrite your old url to new one but it map to the
original route.
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Q9. What are Endpoint, Route and Segment?
• An endpoint is a URL of a resource which can be used to perform a specific
task or functionality.
• A route is a pattern which can be matched to a given endpoints
to redirect requests.
• A route segment is a piece of the URL, as delimited by slashes (/).
Route Eg: [controller]/[action]
Endpoint Eg: GET account/login
Segments Eg: account, login
Copyright Dot Net Tricks Innovation Pvt. Ltd. | All rights Reserved.
Download