DotNet Core
In an ASP.NET Core application, middleware acts as a software component that sits within the request pipeline, handling incoming requests and outgoing responses by performing specific tasks like logging, authentication, authorization, error handling, or serving static files, allowing developers to modularly add functionality to their application as each request passes through a chain of middleware components, executing them in a defined order.
Key points about middleware:
Pipeline processing:
Each request goes through a series of middleware components, with each component having the opportunity to modify the request or generate a response before passing it to the next component in the chain.Customizable functionality:
Developers can create custom middleware to implement specific application logic, providing flexibility to tailor the request handling process to their needs.Built-in middleware:
ASP.NET Core includes a variety of built-in middleware components for common tasks like routing, static file serving, exception handling, and more.Short-circuiting:
A middleware component can choose to "short-circuit" the pipeline, meaning it can stop further processing of the request if necessary, like when a static file is served.
Example of middleware usage:
Authentication middleware:
Checks if a user is authenticated before allowing access to a protected resource.Logging middleware:
Logs details about incoming requests and outgoing responses for debugging purposes.Error handling middleware:
Catches exceptions thrown during request processing and generates custom error pages.
In .NET Core, cross-cutting concerns like logging, error handling, security, and caching are typically managed using a combination of middleware, dependency injection, and Aspect-Oriented Programming (AOP), allowing you to modularize these concerns and apply them consistently across your application without cluttering your core business logic within individual classes.
In .NET Core, "app.Use" refers to a method used to add middleware components to the HTTP request pipeline within an ASP.NET Core application
//for delete item
<input asp-for="CategoryId" hidden />
https://github.com/CodeSeven/toastr
<footer class="fixed-bottom site-footer text-muted bg-dark ">
<div class="container text-center">
© 2022 - WebAppCore6 - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options ) : base(options)
{
}
public DbSet<Category>? Categories { get; set; }
}
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
Linq Join example
var query = (from prod in objProductList
join catg in lstCategory
on prod.CategoryId equals catg.CategoryId
join covr in lstCoverType
on prod.CoverTypeId equals covr.CoverTypeId
select new Product
{
ProductId = prod.ProductId,
Title = prod.Title,
Description = prod.Description,
ISBN = prod.ISBN,
Author = prod.Author,
Price = prod.Price,
ImageURL = prod.ImageURL,
CategoryName = catg.Name,
CoverTypeName = covr.Name
}).ToList();
https://www.c-sharpcorner.com/article/differences-between-scoped-transient-and-singleton-service/