A standard ASP.NET Core application (.NET 11) with the YAF.NET forum integrated as an area. Use it to see how the integration works, or as the starting point for your own site.
- Forum as an area: the complete forum from the
YAFNET.RazorPagespackage runs at/Forums, inside the layout of the site. - One login, one theme: the forum accounts are the accounts of the site. The header shows the login state of the forum on every page, and the theme chosen in the forum admin (including light and dark mode) styles the whole site.
- Your pages, forum data: the home page reads the board statistics and the latest topics through the repositories of the forum.
- Real-time chat: the optional
YAFNET.UI.Chatpackage adds a chat room at/Chat. - Blazor: Blazor Server components run next to the forum, as a routable component and inside a Razor Page.
- Getting started page: the running application explains itself at
/GettingStarted.
Note
The netfx branch contains the .NET Framework version with YAF.NET 3.2.x.
- .NET 11 SDK (or Visual Studio with the ASP.NET workload)
- Microsoft SQL Server (Express and LocalDB work too). MySQL, PostgreSQL and SQLite are supported as well, see Using another database.
- Optional: an SMTP server for the registration and notification mails
-
Get the code
git clone https://github.com/YAFNET/YAF.SampleWebApplication.git cd YAF.SampleWebApplicationOr download the source of a release.
-
Set the connection string
Create an empty database (e.g.
yafnet) and enter the connection string inYAF.SampleApp/appsettings.json:"ConnectionStrings": { "DefaultConnection": "data source=(local);initial catalog=yafnet;Integrated Security=True;TrustServerCertificate=True;" }
To keep the connection string of your machine out of git, put it in
appsettings.Development.json(ignored by git) or in the user secrets:cd YAF.SampleApp dotnet user-secrets init dotnet user-secrets set "ConnectionStrings:DefaultConnection" "<your connection string>"
The user secrets are only read in the
Developmentenvironment (dotnet runand Visual Studio use it). -
Run the application
cd YAF.SampleApp dotnet runOr open
YAF.SampleApp.slnxin Visual Studio and press F5. -
Install the forum
The first request redirects to the installation wizard (
/Forums/Install/Install). It tests the connection, creates the tables and asks for the name of the board and your admin account. When it is done, log in with that account.
| File | What it does |
|---|---|
Program.cs |
Registers YAF.NET (Autofac, services, middleware, hubs), the chat and Blazor |
appsettings.json |
Connection string, mail server and the BoardConfiguration of the forum (Area and StaticFilesRoot put the forum at /Forums) |
Pages/Shared/_Layout.cshtml |
The layout of your own pages, with the theme of the forum |
Pages/Shared/_SiteHeader.cshtml, _SiteFooter.cshtml |
Header and footer of all pages, also of the forum and the chat |
Areas/Forums/Pages/Shared/_Layout.cshtml |
Replaces the forum layout of the package: the site header around the forum navigation |
Areas/Chat/Pages/Shared/_Layout.cshtml |
The same for the chat page |
Pages/Index.cshtml(.cs) |
The home page, reads statistics and the latest topics from the forum |
Pages/GettingStarted.cshtml |
The getting started guide inside the application |
Pages/Counter.razor, Pages/CounterPage.cshtml |
The Blazor demos |
wwwroot/css/site.css |
The styles of the sample pages |
The forum comes from these NuGet packages:
| Package | Contains |
|---|---|
| YAFNET.RazorPages | All forum pages and their static files |
| YAFNET.Data.SqlServer | The data provider for SQL Server |
| YAFNET.UI.Chat | Optional: the chat area |
Replace the YAFNET.Data.SqlServer package with the package of your database, then set the connection string and BoardConfiguration:ConnectionProviderName (both have examples in the comments of appsettings.json):
| Database | Package | ConnectionProviderName |
|---|---|---|
| Microsoft SQL Server | YAFNET.Data.SqlServer |
Microsoft.Data.SqlClient |
| MySQL / MariaDB | YAFNET.Data.MySQL |
MySql.Data.MySqlClient |
| PostgreSQL | YAFNET.Data.PostgreSQL |
Npgsql Data Provider |
| SQLite | YAFNET.Data.Sqlite |
System.Data.SQLite |
For example, for SQLite:
cd YAF.SampleApp
dotnet remove package YAFNET.Data.SqlServer
dotnet add package YAFNET.Data.Sqlite"ConnectionStrings": {
"DefaultConnection": "Data Source=yafnet.db;Version=3;"
},
"BoardConfiguration": {
"ConnectionProviderName": "System.Data.SQLite",
...
}- Your own pages use
BoardContext.Currentto get the current forum user, the board settings and the services of the forum. SeePages/Shared/_SiteHeader.cshtmlandPages/Index.cshtml.cs. - Forum pages: a file at the same path as in the
YAFNET.RazorPagespackage replaces the one of the package, asAreas/Forums/Pages/Shared/_Layout.cshtmldoes. Start from the original of the same version. - Themes: choose a theme in Admin › Board Settings, or build your own with @yafnet/theme-kit, see Customization.
- Update the
YAFNET.*packages to the same new version (all of them together). - Compare the files you have overridden (e.g.
Areas/Forums/Pages/Shared/_Layout.cshtml) with the originals of the new version and take over their changes. - Start the application: the first request upgrades the database automatically. Back up the database first.
See Upgrade YAF.NET v4.x.x for details.
- Integrate YAF.NET into an existing ASP.NET Core application: the same steps for your own project
- BoardConfiguration settings
- YAF.NET wiki and YAF.NET source
- Support forum