نموذج أساسي لـ Nano ASP.NET SaaS
بيانات اعتماد المسؤول (جميع المستأجرين): admin@email.com / Password123!
تتم إعادة تعيين البيانات النموذجية كل ساعة
نموذج أساسي لـ Nano ASP.NET SaaS
عام
.حل .NET
واجهة مستخدم Vue
واجهة المستخدم في React
صفحات Razor
صفحات Razor

نظرة عامة على مشروع Razor Pages (MVC)

صفحات Razor is a page-focused framework for building server-rendered web applications with ASP.NET Core. Like the Model-View-Controller (MVC) pattern, it supports separation of application logic and presentation. However, Razor Pages organizes code around individual pages, each typically consisting of a .cshtml file and an associated PageModel code-behind file.

Razor Pages is a practical choice when you want server-rendered HTML, straightforward routing, and an integrated ASP.NET Core development experience without building a separate single-page application (SPA).

Nano’s RazorApp project is an ASP.NET Core web application that shares the same Domain, Application, and Infrastructure code as the WebAPI project. Both configurations reuse the core business logic and backend services, but differ in how they present the UI and handle authentication.

For background on the shared architecture, start with the ASP.NET Core Web API guide and the .NET solution overview.

This guide focuses on the differences between Nano’s Razor Pages UI and its SPA configuration, which uses WebAPI as the presentation layer for a separate React or Vue frontend.

الـ RazorApp project may also show missing frontend development dependencies in the IDE. These dependencies are used to customize and rebuild the theme assets; they may not be required simply to run the application. See the Razor theme and styling guide for details.

The main differences between Nano’s SPA and Razor Pages configurations are the page-based UI and the authentication mechanism.

Razor Pages routing is registered in the application’s startup configuration using MapRazorPages(). ASP.NET Core discovers Razor Pages under the Pages directory and maps routes according to the page file and folder structure, with route conventions and attributes available for customization.

Each page typically has two files:

  • .cshtml — defines the page’s HTML markup using Razor syntax.
  • .cshtml.cs — contains the associated PageModel class and server-side page logic.

This structure keeps the markup and page-specific logic together while allowing shared application services and business logic to remain in the other projects.

Nano’s Razor Pages configuration uses cookie-based authentication for its server-rendered UI, rather than relying on JWT bearer tokens as the primary authentication mechanism for the frontend.

The main differences are:

Cookie settings: في RazorApp project’s ServiceCollectionExtensions, cookie authentication settings replace the JWT authentication configuration used by the SPA-oriented setup.

Current tenant and user: الـ CurrentTenantUserService obtains the current user’s identity and claims from the authenticated request’s principal, which is established through cookie authentication. In a multi-tenant configuration, tenant context must also be resolved according to Nano’s tenant-resolution logic.

Login service: The RazorApp configuration uses a login service built around ASP.NET Core Identity’s SignInManager. When a user signs in successfully, the application establishes an authentication session using a cookie. The browser sends that cookie with subsequent requests, allowing ASP.NET Core to identify the authenticated user.

This replaces the SPA’s usual login flow, in which the frontend obtains and manages tokens through the TokenService في Infrastructure/Auth.

Nano’s Razor Pages UI organizes page-specific markup and logic under the Pages directory. Routes generally follow the folder and file structure, while shared layouts and partial views provide common UI elements.

The main Layout view defines the application’s shared page structure, including the side navigation, top navigation bar, footer, and references to CSS and JavaScript resources.

Third-party UI components, such as charts, range sliders, and data tables, may require their own CSS and JavaScript files. Nano organizes vendor assets under:

wwwroot/assets/vendor

When adding a new frontend package or component, include its required assets and reference them in the layout or the relevant page, as appropriate. Avoid loading the same resources globally if they are only needed on specific pages.

Nano also includes a Guest Layout for public-facing pages, such as login and password recovery, that do not use the main authenticated application layout.

The application pages are organized into feature-specific folders, including:

  • Authentication
  • Profile
  • المنتجات
  • Users
  • المستأجرون

Each Razor Page can have a code-behind file containing its PageModel. Use the PageModel to prepare data required for the initial page render, handle page requests, and coordinate with application services.

DTOs and validation attributes can be used to define input models and support validation. Where configured, jQuery Unobtrusive Validation can use these rules to provide client-side validation alongside server-side validation.

Although Razor Pages renders HTML on the server, Nano also uses AJAX requests to call API controllers for many CRUD operations. This allows actions such as creating, editing, or deleting records to update the UI without requiring a full page reload.

Page-specific JavaScript is organized under:

wwwroot/assets/js/pages

Individual pages can include their required scripts through a Razor Scripts section, which is rendered by the layout when configured to do so.

Template Resources contains sample UI elements that you can use as a starting point when developing the application. The samples are divided into two categories:

  • واجهة المستخدم الأساسية — standard Bootstrap components, such as form inputs, modals, and buttons.
  • واجهة المستخدم الموسعة — components that use third-party libraries, such as charts and range sliders.

Some sample components include their JavaScript directly in the page to demonstrate their functionality. When adapting these examples for production features, consider moving reusable logic into the appropriate shared or page-specific JavaScript files.

Continue to the Razor Pages Theme & Styling guide to learn how Nano organizes its static assets, stylesheets, and frontend theme.