Q11. What is [AllowAnonymous] Attribute in dotnet 8?
Q12. What are the benefits of .net core application over asp.net applications?
Q13. Describe the usage of Program.cs in dotnet 8 application?
Q14. How to create Custom middleware in dotnet 8?
Q15. What is the difference between calling a method in async and multi-threading?
=======================================================================
Q11. What is [AllowAnonymous] Attribute in dotnet 8?
Answer:
This attribute allows unauthenticated users to access specific actions, even if the controller is secured with
[Authorize]. eg Login Page,
Register Page
Logout etc
=======================================================================
Q12. What are the benefits of .net core application over asp.net applications?
Answer:
asp.net
1. Build for Windows only.
2. Multiple versions per machine
3. Not open-source
4. Require external IOC container.
5. Can be hosted only on IIS
6. Containerization is possible with limitation (only windows container and not cross platform)
7. Relatively slower
8. asp.net is not the first choice of microservices.
.net Core
1. Build for Windows, macOS, or Linux and is platform independent.
2. Multiple versions per machine.
3. Open-Source - It is an open-source and community-focused web framework.
4. Support Built-In Dependency Injection - It supports built-in Dependency Injection.
5. Hosting - It has the ability to host on IIS, Apache, Docker, nginx, or Self Hosting
6. Containerization is possible thus you can move your application on docker and then on kubernetes.
7. Relatively faster.
8. Microservices
=======================================================================
Q13. Describe the usage of Program.cs in dotnet 8 application?
Answer:
In .NET 8,
Program.cs is the entry point of the application. It uses the minimal hosting model, so there’s no longer a separate Startup.cs. Everything — dependency injection (DI), middleware, configuration, and routing — is set up directly in Program.cs.Typical Usage:
-
Create the builder and register services
-
builder.Servicesis used to register dependencies, controllers, authentication, EF DbContext, etc.
-
-
Build the application
-
Configure the middleware pipeline
-
Middleware like authentication, authorization, exception handling, static files, Swagger, etc. are configured in order.
-
-
Map endpoints
-
Controllers, minimal APIs, health checks, etc. are wired here.
-
-
Run the app
=======================================================================
Q14. How to create Custom middleware in dotnet 8?
Answer:
1. Visual Studio include a template to create a custom middleware. Right click on a project and add a new item of type middleware.
2. A new Middleware class will be generated with Constructor, Invoke Method, and an Extension method. This Extension method will be responsible to make my new middleware capable of getting added in program.cs pipeline.
3. Register the middleware in pogram.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseCustomMiddleware();
=======================================================================
Q15. What is the difference between calling a method in async and multi-threading?
Answer:
A-Synchronicity and parallelism are two different concepts.
Async is to make request non-blocking, and it is single thread by default. it means we are not stopping caller to move ahead in code. this is concept of concurrency. Async await keyword can be used.
Parallelism, or use of all threads is use of all cores and their threads. this is usually done to bring performance. for multi core system we can have parallelism in picture. Task is the keyword for parallelism. this is the concept of parallelism (not concurrency)
No comments:
Post a Comment