Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

Create an Application With Confinity

In this guide we will show you how to create your first Confinity application. In this tutorial we use Confinity with all the default settings and a SQLite database.

What you need

  • .Net SDK v5.0 (or newer) installed (Link)
  • a cup of coffee or tea

Let's get started

First, create a new MVC application by executing the following command in your desired project location folder.

dotnet new mvc

You can now add Confinity by running

dotnet add package Confinity.WebUI

Now lets register all Confinity services by opening your Startup.cs and call AddConfinity() in the ConfigureServices method.


var builder = WebApplication.CreateBuilder(args);

var confinityOptions = new ConfinityOptions(new SqliteDatabaseProviderConfiguration());
builder.Services.AddConfinity(builder, confinityOptions, moduleBuilder => { });

Also add a new variable _webHostEnvironment in the startup class and set the variable in the Startup Method.


private readonly IWebHostEnvironment _webHostEnvironment;
private readonly IConfiguration _configuration;

public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
{
    _webHostEnvironment = webHostEnvironment;
    _configuration = configuration;
}

In the Configure method, call app.UseConfinity() and endpoints.MapConfinity().


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
        app.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseConfinity(env);

    app.UseRouting();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapConfinity();
    });
}

Last but now least, we have to extend the appsettings.json with the required settings, namely the database connection string and the path to the JWT key file.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Confinity": {
    "Database": {
      "DbProvider": "Sqlite",
      "ConnectionString": "DataSource=./docs.db"
    },
    "AuthJwk": {
      "Filepath": "./authJsonWebKey.json"
    }
  }
}

To create a new JWT key file you can use a tool like mkjwk.

First login

That's it. You can now start your application and browse to localhost:5000/.confinity. And log in using the username confinity and password confinity.

Prev
Core Concepts
Next
Glossary