Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. When a web page is called, the Razor view engine executes the server-based code inside the page before it returns the page to the browser.
The Razor syntax is a template markup syntax, based on the C# programming language, that enables the programmer to use an HTML construction workflow. Instead of using the ASP.NET Web Forms (.aspx) markup syntax with <%= %> symbols to indicate code blocks, Razor syntax starts code blocks with an @ character and does not require explicit closing of the code-block. The Razor parser is smart enough to infer this from your code. This enables a compact and expressive syntax which is clean, fast and fun to type.
ASP.NET helpers are components that can be accessed by single lines of Razor code. You can build your own helpers using Razor syntax, or use built-in ASP.NET helpers. Razor’s @helper syntax provides a convenient way to encapsulate rendering functionality into helper methods that you can re-use within individual view templates, or across all view templates within a project.
Below is a short description of some useful Razor helpers:
An ASP.NET Core application is a console application that contains a web server that serves as the entry point for a request. Microsoft provides, by default, a cross-platform web server called Kestrel. By adding an ASP.NET Core web server to your .NET Core app, your application can run as a web application. ASP.NET Core is composed of many small libraries that you can choose from to provide your application with different features. Some of the libraries are common and will appear in virtually every application you create, such as the ones for reading configuration files or performing logging. Other libraries build on top of these base capabilities to provide application-specific functionality, such as third-party logging-in via Facebook or Google.
ASP.NET Core application can act as the server-side application for a variety of different clients: it can serve HTML pages for traditional web applications, it can act as a REST API for client-side SPA applications, or it can act as an ad-hoc RPC service for client applications.
In a traditional web application built on ASP.NET, IIS is tightly coupled with the application and calls into specific points of your application.
When you build a web application with ASP.NET Core, browsers will still be using the same HTTP protocol to communicate with your application. The request process starts when a user’s browser sends an HTTP request to the server. A reverse-proxy server captures the request, before passing it to your application. In Windows, the reverse-proxy server will typically be IIS, and on Linux or macOS it might be NGINX or Apache. The request is forwarded from the reverse proxy to your ASP.NET Core web application. ASP.NET Core web application itself encompasses everything that takes place on the server to handle a request, including verifying the request is valid, handling login details, and generating HTML.
ASP.NET Core comes with advanced request processing through the pipeline configuration of the .NET Core middleware elements.
In ASP.NET Core, middlewares are C# classes that can handle an HTTP request or response. Middleware can either:
For example, a piece of logging middleware might note down when a request arrived and then pass it on to another middleware. Meanwhile, an image resizing middleware component might spot an incoming request for an image with a specified size, generate the requested image, and send it back to the user without passing it on.
The most important piece of middleware in most ASP.NET Core applications is the MvcMiddleware. This normally generates your HTML pages and API responses. Like the image resizing middleware, it typically receives a request, generates a response, and then sends it back to the user.
The following sequence of tutorials for an introduction to developing ASP.NET Core apps:
1. Follow a tutorial for the app type you want to develop or maintain.
2. Follow a tutorial that shows how to do basic data access.
© 2022 Digcode.com