📄 ApplicationUser.cs Documentation
Welcome to the detailed documentation for the ApplicationUser.cs file in the IrbyImaging project. This document covers everything from a high‑level overview to code snippets, UML diagrams, and usage examples. Whether you’re extending the user model, integrating ASP.NET Core Identity, or simply looking to understand how ApplicationUser fits into your application, you’ll find all the context you need below.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Data Model: ApplicationUser
- UML Class Diagram
- Key Functional Areas
- Extending ApplicationUser
- Integration in Startup / Program
- Usage Examples
- Conclusion & Next Steps
1. Overview & Purpose
ApplicationUser is your custom user entity for ASP.NET Core Identity.
By inheriting from IdentityUser, it:
- 📌 Leverages built‑in authentication/authorization.
- 🔑 Provides all standard user fields (
Id,UserName,Email, etc.). - 🌱 Serves as the foundation for any additional profile or application‑specific data.
File path: IrbyImaging/ApplicationUser.cs
Namespace: IrbyImaging
using Microsoft.AspNetCore.Identity;
namespace IrbyImaging
{
public class ApplicationUser : IdentityUser
{
// ✔️ Extend with custom properties here
}
}
2. Dependencies & Technologies
| Dependency | Version / Description |
|---|---|
| Microsoft.AspNetCore.Identity | Core package providing IdentityUser, roles, and stores |
| .NET Standard / .NET 6+ | Target framework for ASP.NET Core applications |
| Entity Framework Core | (Typically used as the Identity store in EF-backed projects) |
- IdentityUser lives in the
Microsoft.AspNetCore.Identitynamespace. - You’ll often combine this with Entity Framework Core to persist users to a SQL database.
3. Data Model: ApplicationUser
Because ApplicationUser inherits everything from IdentityUser, it includes:
| Property | Type | Description |
|---|---|---|
Id |
string |
Primary key (GUID by default) |
UserName |
string |
Login name |
NormalizedUserName |
string |
Normalized (uppercase) username for lookups |
Email |
string |
User’s email address |
NormalizedEmail |
string |
Normalized email for lookups |
EmailConfirmed |
bool |
Has the user confirmed their email? |
PasswordHash |
string |
Hashed password |
SecurityStamp |
string |
Token to invalidate sessions |
ConcurrencyStamp |
string |
For optimistic concurrency control |
PhoneNumber |
string |
User’s phone number |
PhoneNumberConfirmed |
bool |
Has the user confirmed their phone? |
TwoFactorEnabled |
bool |
Is 2FA enabled? |
LockoutEnd |
DateTimeOffset? |
When the lockout ends (if locked) |
LockoutEnabled |
bool |
Can this user be locked out? |
AccessFailedCount |
int |
Number of failed login attempts |
Tip: Extend this class with your own properties, e.g.,
FirstName,LastName,ProfilePictureUrl, etc.
4. UML Class Diagram
classDiagram
Microsoft.AspNetCore.Identity.IdentityUser <|-- IrbyImaging.ApplicationUser
class IdentityUser {
+ string Id
+ string UserName
+ string NormalizedUserName
+ string Email
+ string NormalizedEmail
+ bool EmailConfirmed
+ string PasswordHash
+ string SecurityStamp
+ string ConcurrencyStamp
+ string PhoneNumber
+ bool PhoneNumberConfirmed
+ bool TwoFactorEnabled
+ DateTimeOffset? LockoutEnd
+ bool LockoutEnabled
+ int AccessFailedCount
}
class ApplicationUser {
<<inherited>>
// Add custom profile properties here
}
5. Key Functional Areas
- Authentication & Authorization
- Via
UserManager<ApplicationUser>andSignInManager<ApplicationUser>.
- Via
- Persistence
- Stored in
AspNetUserstable when using EF Core.
- Stored in
- Extensibility
- Easily add business‑specific fields (e.g., roles, claims, preferences).
6. Extending ApplicationUser
To capture more user data, simply add properties:
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; } // 📛 User’s first name
public string LastName { get; set; } // 🏷️ User’s last name
public DateTime DateOfBirth { get; set; }// 🎂 Optional DOB
}
Remember: After adding new properties, update your EF Core migrations:
dotnet ef migrations add ExtendApplicationUser dotnet ef database update
7. Integration in Startup / Program
Register Identity in Startup.cs (ASP.NET Core 3.x/5) or Program.cs (.NET 6+):
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
// ✨ Identity options (password, lockout, etc.)
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddControllersWithViews();
}
8. Usage Examples
8.1 Register a New User
public class AccountController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
public AccountController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}
[HttpPost]
public async Task<IActionResult> Register(RegisterViewModel vm)
{
if (!ModelState.IsValid) return View(vm);
var user = new ApplicationUser
{
UserName = vm.Email,
Email = vm.Email,
// FirstName = vm.FirstName, // if extended
// LastName = vm.LastName
};
var result = await _userManager.CreateAsync(user, vm.Password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
}
return View(vm);
}
}
8.2 Fetch Current User
public async Task<IActionResult> Profile()
{
var user = await _userManager.GetUserAsync(User);
return View(user);
}
9. Conclusion & Next Steps
ApplicationUser.cs is your primary user entity in the IrbyImaging application.
By inheriting from IdentityUser, it provides an out‑of‑the‑box authentication and authorization model, while remaining fully extensible for your domain needs.
🚀 Next Steps:
- Add custom properties (e.g., preferences, avatars).
- Create corresponding EF Core migrations.
- Implement custom claims or roles as needed.
- Secure API endpoints by injecting
UserManager<ApplicationUser>&SignInManager<ApplicationUser>.
Whether you’re building a small imaging tool or a large enterprise system, ApplicationUser is your springboard for a secure, robust user management solution.
Happy coding! 🎉
— IrbyImaging Team