Please enable JavaScript.
Coggle requires JavaScript to display documents.
Advanced .NET - Coggle Diagram
Advanced .NET
Webapp with Razor Pages
What is Razor Pages?
Is a server-side, page-focused framework for building dynamic, data-driven web sites in cross platform
-
What is Razor?
-
Razor syntax consists of Razor markup, C# and HTML. Files contains Razor have .cshtml extension
Different types of Razor
Razor Page (Single Page Model) only cshtml file
- Razor C# code block is denoted by {...}
Razor Page (Page Model) cshtml + cshtml.cs files
- Any code related to data processing is placed in PageModel (cshtml.cs) file
-
Other files
-
_ViewStart.cshtml: contains code that executes after the code in any content page in the same folder or any child folders
-
Partial Pages can be used to break up complex pages into smaller unit. Partial Pages do not take part in routingSyntax for import Partial Page:
Razor syntax
-
All code block must appear within {...}
Comments within a code block can be denoted by // or / ... / or *...*@
More about Page Model
-
Benefits:
- Reduce complexity of UI
- Help automated unit testing
- Allow concurrency working among team members
- Small and Reusable units of code that aids maintenance and scalability
PageModel class is a combination of Controller and ViewModel called Page Controller pattern which is one-to-one mapping between pages and their controllers
PageModel is an implementation of Presentation Model pattern not MVVM pattern because Presentation and Model does not share the same layer
Handler methods
Handler methods are automatically executed as a result of a request. Razor Pages framework uses a naming convention to select method to execute
The name of the method which is prefixed with "On" such as OnGet(), OnPost(), OnPut(),...
Handler method also have optional asynchronous equivalents and framework are the same handlers: OnGetAsync(), OnPostAsync(),...
-
ViewData
-
-
-
ViewBag is a wrapper around ViewData and provides and alternative way to access ViewData contents using dynamic properties or string-based indexes
Action Results
Commonly used as return type of handler methods and responsible for generating response and status code
-
Tag Helpers
-
-
Tag helpers also emit attributes that provide support client-side validation with attribute based data annotations
-
Startup config
In Startup class, ConfigureServices called before Configure method. If you want to config the root folder of Razor you can do it in ConfigServices method
The appsetting.json file includes section configures logging and configure value. It can be read by Configuration object
-
Form & Validation
-
There are three ways to access user input:
- Request.Form collection via string-based index
- Model binding from handler parameters
- Model binding from public properties
-
-
For client-side validation, must include jQuery validation within the page using partial import
Model Binding
Model binding is a process taking values from HTTP request and maps them to handler method parameters or PageModel properties
Binding values to PageModel properties can be done using [BindProperty] attribute at the top of property or [BindProperties] attribute at top of class for binding all properties
State Management
Enabling Session manage by calling service.AddSession() in ConfigureServices method and app.UseSession() in Configure method
-
-
Real-time communication
-
What is SignalR
-
-
SignalR using Hubs API to push notification and support multiple channels such as WebSocket, server-sent events and long polling
Support multiple clients like C#, C++, Java, JavaScript
-
-
Hubs
-
You can pass strongly-typed parameters to methods, which enables model binding
-
Client and Server try to match the name and parameters of method in each other. Data passing is deserialized with config protocols
-
SignalR middleware requires some services which are configured by calling services.AddSignalR() and mapping endpoint by app.UseEndpoints()
-
-
Handle connection
SignalR Hub API provides OnConnectedAsync and OnDisconnectedAsync virtual methods to manage and track connections
OnDisconnectedAsync has Exception parameter which is null when client call connection.stop() but if client is disconnected due to an error the exception params will contain description
Hub Filters
-
-
Configure hub filters can be applied globally or per hub by using AddFilter() in options params of AddSignalR() method for global register or AddHubOption<HubName> for per hub configure
-
-
Networking
Basic networking
Platform, Client, Server, IP, Port, Protocol
-
-
-
-
-
-
-
-
-