This is a Blazor .NET 8 application leverage Microsoft ASP.NET Core Identity with some customizations to use on-prem Active Directory to do password checking.
Since this project leverages Identity, a DB is created to store user information. Since AD is used for password checking, the password is never stored in the DB. Only user information pertinent to the app is stored.
You can edit
/Services/Auth/AdUserService.cs
to alter thePrincipalContext
calls to customize how the app connects to AD. By default, it uses the 'default' domain of the host and binds to the base DN.
System.DirectoryServices
being used for validation.Users
role, it is not utilized by default.<AuthorizedView>
to control what's shown to anonymous users and logged in users.dotnet restore
to restore the NuGet packages<UserSecrets>
line in the .csproj file.And you really should be!
- Regenerate the user secrets via
dotnet user-secrets init
. Visual Studio users can right click on the project and select 'Manage User Secrets'. Otherwise, look in%APPDATA%\Microsoft\User Secrets
in Windows.- Copy the contents of
appsettings.Example.json
into the user secrets file and edit accordingly.
appsettings.Example.json
into a new file called appsettings.Development.json
and edit accordingly.dotnet build
/Data/DbSeed.cs
and customize the users accordingly. They must be valid AD users.dotnet run -- seed=True
It is highly recommended to use Visual Studio, Rider, or VS Code for debugging of the app.
- The app can be run from the command line with
dotnet run
in the top project directory.
One major caveat of Interactive Render Modes in Blazor is the lack
of access to HttpContext
. Server mode runs over a SignalR circuit, and WASM runs
in the client. Because of this, Identity uses Static Server Rendering with its razor
components and code.
If you want to enable Interactivity on a per-component basis, then no changes are
required. Just make sure to not add any @rendermode
to any Identity pages under /Component/Accounts/Pages
.
However, if you want to enable Interactivity globally, then some changes are required:
@code {}
block in /Components/App.razor
@rendermode="RenderModeForPage"
to both <HeadOutlet />
and <Routes />
Note: Any page starting with
/account
will be rendered as SSR with this method, as these pages rely on access toHttpContext
which is not present otherwise.