microsoft/migrating-global-asax
> Migrates Global.asax application lifecycle events to ASP.NET Core middleware, startup configuration, and Program.cs. Use when upgrading ASP.NET Framework apps containing Global.asax or Global.asax.cs files. Triggers for "migrate Global.asax", "convert application events", "move Application_Start to Program.cs", "replace Global.asax with middleware", and ASP.NET-to-Core migration involving request lifecycle, error handling, or session management.
npx skills add https://github.com/microsoft/upgrade-agent-plugins --skill migrating-global-asax
Converts Global.asax.cs application lifecycle event handlers into ASP.NET Core equivalents: service registration in Program.cs, custom middleware, and built-in middleware configuration.
Migration Progress:
- [ ] Step 1: Verify Global.asax exists
- [ ] Step 2: Audit event handlers
- [ ] Step 3: Triage each event
- [ ] Step 4: Convert events using mapping
- [ ] Step 5: Add required using statements
- [ ] Step 6: Remove Global.asax files
- [ ] Step 7: Verify build and behavior
Check if the project still has Global.asax.cs. If not, inform the user there is nothing to migrate and stop.
Inventory all application events in Global.asax.cs:
Application_StartApplication_EndApplication_ErrorApplication_BeginRequest / Application_EndRequestSession_Start / Session_EndDetermine whether each event is still needed. ASP.NET Core handles some concerns (like routing registration) through its built-in pipeline, so not every handler needs a direct replacement.
Apply the Event Conversion Mapping to migrate each needed handler to its ASP.NET Core equivalent.
Add any using statements needed by the new middleware or services in Program.cs.
Delete both Global.asax.cs and Global.asax from the project. ASP.NET Core does not use them — keeping them causes confusion and they are never loaded by the runtime.
Build the project and confirm no compilation errors. Verify that the application behavior is preserved.
| Global.asax Event | ASP.NET Core Pattern | Why |
|---|---|---|
| Application_Start | Service registration in Program.cs | The DI container and pipeline replace manual initialization |
| Application_End | IHostApplicationLifetime.ApplicationStopping | Host lifetime events replace the application-level shutdown hook |
| Application_Error | app.UseExceptionHandler() | Built-in middleware provides structured error handling with logging |
| Application_BeginRequest | Custom middleware before await next() | The middleware pipeline replaces per-request event hooks |
| Application_EndRequest | Custom middleware after await next() | Code after next() runs on the response path |
| Session_Start / Session_End | builder.Services.AddSession() + app.UseSession() | ASP.NET Core manages sessions through explicit middleware opt-in |
// Before: Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
// After: Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.MapControllers();
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
lifetime.ApplicationStopping.Register(() =>
{
// Cleanup logic from Application_End
});
app.UseExceptionHandler("/Home/Error");
app.Use(async (context, next) =>
{
// Logic from Application_BeginRequest
await next();
// Logic from Application_EndRequest
});
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
app.UseSession();
IHostedService depending on whether they are request-scoped or application-scoped.UseSession() and verify cookie settings.Global.asax.cs and Global.asax files removed from projectTake microsoft/migrating-global-asax 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.