-
Notifications
You must be signed in to change notification settings - Fork 31
ASP.NET Server
Jihad Khawaja edited this page Mar 31, 2024
·
23 revisions
- dotnet 7.0, You can use Visual Studio 2022 17.4 or higher or install dotnet-7.0 SDK and runtime and use your favorite editor like Visual Studio Code (Required)
- ASP.NET and web development workload
- PostgreSQL (Npgsql) Or SQL Server (Required)
- pgAdmin Or SQL Server Management Studio (SSMS) to view and edit the database (optional)
- MobileChat Server NuGet Package
- Inside the solution apply this command in the developer console in Visual Studio when you first launch the project or in a terminal inside project src folder root.
dotnet restore
- Set multiple project startup by right clicking the solution and then properties and select multiple startup project. Select MobileChat.MAUI and MobileChat.Server to start, Position the MobileChat.Server above MobileChat.MAUI to start before it.
- Create appsettings.json (Production) and appsettings.Development.json (Development) files in the server project root then set the "Build Action" to "Content" and "Copy to Output Directory" to "Copy if newer" for each file.
- Paste these into appsettings.json and configure your connection parameters.
If you're using Sql Server your appropriate connection strings and select SqlServer instead of Postgres in Program.cs in services.AddMobileChatServices(...).
The JWT Secret key should be a minimum of 128 bits i.e. (16 bytes)
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/log.txt",
"rollingInterval": "Day"
}
},
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
}
}
]
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=5432;User Id=postgres;Password=yourpassowrd;Database=mobilechatdb;"
},
"Secrets": {
"Jwt": "your-secret-key-here-not-less-than-32-characters"
}
}
- Paste these into appsettings.Development.json and configure your connection parameters
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=5432;User Id=postgres;Password=yourpassowrd;Database=mobilechatdb;"
}
}
- Set your database connection strings in appsettings.json and appsettings.Development.json
- Test your database connection, in the Package Manager Console (Ctrl+`)
Add-Migration [your migration name]
Or CLI
dotnet ef migrations add init
- Updating the database can be automated by setting autoMigrateDatabase param to true in the Server Program.cs or you can do it manually using
Update-Database
Or CLI
dotnet ef database update
- If your database is setup correctly you should find the database along with your models tables added to it.
- If your database not updating delete your old database and try again otherwise open an issue.