What is the ASP.NET Core?
ASP.NET Core is not an upgraded version of ASP.NET. ASP.NET Core is completely
rewriting that work with .net Core framework. It is much faster, configurable,
modular, scalable, extensible and cross-platform support. It can work with both .NET
Core and .net framework via the .NET standard framework. It is best suitable for
developing cloud-based such as web application, mobile application, IoT application.
What is the startup class in ASP.NET core?
Startup class is the entry point of the ASP.NET Core application. Every .NET Core
application must have this class. This class contains the application configuration
rated items. It is not necessary that class name must "Startup", it can be anything, we
can configure startup class in Program class.
What is the use of ConfigureServices method of startup
class?
This is an optional method of startup class. It can be used to configure the services
that are used by the application. This method calls first when the application is
requested for the first time. Using this method, we can add the services to the DI
container, so services are available as a dependency in controller constructor.
What is the use of the Configure method of startup
class?
It defines how the application will respond to each HTTP request. We can configure
the request pipeline by configuring the middleware. It accepts IApplicationBuilder as
a parameter and also it has two optional parameters: IHostingEnvironment and
ILoggerFactory. Using this method, we can configure built-in middleware such as
routing, authentication, session, etc. as well as third-party middleware.
What is middleware?
It is software which is injected into the application pipeline to handle request and
responses. They are just like chained to each other and form as a pipeline. The
incoming requests are passes through this pipeline where all middleware is
configured, and middleware can perform some action on the request before passes it
to the next middleware. Same as for the responses, they are also passing through the
middleware but in reverse order.
What is the use of "Map" extension while adding
middleware to ASP.NET Core pipeline?
It is used for branching the pipeline. It branches the ASP.NET Core pipeline based on
request path matching. If request path starts with the given path, middleware on to
that branch will execute.
What is routing in ASP.NET Core?
Routing is functionality that map incoming request to the route handler. The route
can have values (extract them from URL) that used to process the request. Using the
route, routing can find route handler based on URL. All the routes are registered
when the application is started. There are two types of routing supported by ASP.NET
Core
The conventional routing
Attribute routing
The Routing uses routes for map incoming request with route handler and Generate
URL that used in response. Mostly, the application having a single collection of
routes and this collection are used for the process the request. The RouteAsync
method is used to map incoming request (that match the URL) with available in route
collection.
How to enable Session in ASP.NET Core?
The middleware for the session is provided by the package
Microsoft.AspNetCore.Session. To use the session in ASP.NET Core application, we
need to add this package to csproj file and add the Session middleware to ASP.NET
Core request pipeline.
public class Startup
public void ConfigureServices(IServiceCollection services)
….
….
services.AddSession();
services.AddMvc();
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
….
….
app.UseSession();
….
….
What are the various JSON files available in ASP.NET
Core?
There are following JSON files in ASP.NET Core :
global.json
launchsettings.json
appsettings.json
bundleconfig.json
bower.json
package.json
What is Kestral?
Ans: Kestrel is a cross-platform web server for ASP.NET Core based on libuv,
a cross-platform asynchronous I/O library. Kestrel is the web server that is
included by default in ASP.NET Core new project templates. If your
application accepts requests only from an internal network, you can use
Kestrel by itself.
If you expose your application to the Internet, you must use IIS, Nginx, or
Apache as a reverse proxy server. A reverse proxy server receives HTTP
requests from the Internet and forwards them to Kestrel after some preliminary
handling. The most important reason for using a reverse proxy for edge
deployments (exposed to traffic from the Internet) is security. Kestrel is
relatively new and does not yet have a full complement of defenses against
attacks.