microsoft/migrating-aspnet-identity
> Migrates ASP.NET MVC Identity to ASP.NET Core Identity, updating IdentityDbContext, UserManager, SignInManager, authentication middleware, and OWIN cleanup. Use when upgrading ASP.NET MVC projects that use Identity authentication, migrating Identity-based login systems, or converting OWIN-based auth to ASP.NET Core middleware. Triggers for Identity migration, auth upgrade, UserManager refactor, IdentityDbContext conversion, and OWIN removal.
npx skills add https://github.com/microsoft/upgrade-agent-plugins --skill migrating-aspnet-identity
Migrates ASP.NET MVC Identity to ASP.NET Core Identity: DbContext conversion, service registration, namespace updates, API changes, and OWIN cleanup.
Verify the project uses ASP.NET Identity (e.g., references Microsoft.AspNet.Identity or IdentityDbContext). If not, skip and inform the user there is nothing to do.
Migration Progress:
- [ ] Step 1: Install required packages
- [ ] Step 2: Update IdentityDbContext
- [ ] Step 3: Register DbContext and Identity in Program.cs
- [ ] Step 4: Add Identity middleware
- [ ] Step 5: Update Identity API usage
- [ ] Step 6: Update AccountController
- [ ] Step 7: Clean up OWIN identity code
Ensure these NuGet packages are installed in the project (version major should match project's target framework):
Microsoft.AspNetCore.Identity.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.SqlServerMicrosoft.AspNetCore.Identity.UIMicrosoft.AspNetCore.Authentication.Cookies (latest version)Find the DbContext class inheriting IdentityDbContext and:
web.config or app.config and add it to appsettings.json under ConnectionStrings with the same name (if not already present).Microsoft.AspNet.Identity, System.Web.Identity) with Microsoft.AspNetCore.Identity.DbContextOptions instead of a connection string.When refactoring DbContext and related models, only change types that differ in ASP.NET Core Identity. Preserve all business logic unrelated to the identity system — removing it would break application behavior that has nothing to do with the migration.
Before:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext() : base("DefaultConnection")
{
}
}
After:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
// ... other DbSets and configuration
}
Register the DbContext in the Program.cs file using connection string name you discovered earlier and correct model class names:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("ConnectionStringName")));
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Add necessary using statements (e.g., using Microsoft.Extensions.Configuration;) as needed.
Ensure Program.cs contains the Identity middleware in the correct order:
app.UseAuthentication();
app.UseAuthorization();
Update identity API calls across all .cs and .cshtml files:
Microsoft.AspNet.Identity, System.Web.Identity) with Microsoft.AspNetCore.Identity.User.Identity.GetUserId() with UserManager.GetUserId(User).Html.BeginForm("Login", "Account", FormMethod.Post) with tag helpers: <form asp-action="Login" asp-controller="Account" method="post"> in Razor views under Views/Account.Update the AccountController constructor to inject UserManager<ApplicationUser> and SignInManager<ApplicationUser> (use the project's actual IdentityUser subclass as the generic parameter).
If the old constructor had legacy identity-related parameters (e.g., ApplicationUserManager), replace them with the new types and update all corresponding properties and references.
Remove any OWIN code that registered identity classes. If Startup.cs and Startup.Auth.cs are empty or have no remaining non-identity configuration, delete them. If other OWIN configuration remains, propose migrating it to ASP.NET Core middleware and call the feature instructions tool for OWIN removal guidance if the user agrees.
Take microsoft/migrating-aspnet-identity from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.