ASP.NET WebForms(ASPX)项目迁移至ASP.NET Core 2.0的可行性与方案咨询
Hey there, let's tackle your questions clearly and based on official Microsoft guidelines:
First off, ASP.NET WebForms (.aspx pages) are not supported in ASP.NET Core 2.0 (or any later versions of ASP.NET Core). This is a deliberate design choice—ASP.NET Core is a ground-up rewrite of the framework that abandons the WebForms control model, page lifecycle, and dependency on the System.Web namespace entirely.
Microsoft's official documentation explicitly states that WebForms isn't part of the ASP.NET Core ecosystem. If you're looking for a server-side UI alternative with similar productivity benefits, the official recommendations are Razor Pages (great for page-focused apps) or ASP.NET Core MVC (ideal for layered, complex applications).
Here's the structured approach outlined in Microsoft's official docs:
- Assess your existing project
Start by mapping out your WebForms app's core features: note any WebForms-specific controls (likeGridView,UpdatePanel), dependencies onSystem.WebAPIs, and third-party controls. Create a priority list of features to migrate first. - Choose your target UI framework
Pick between Razor Pages or MVC based on your app's structure. Razor Pages aligns best with page-centric WebForms apps, while MVC suits apps with complex routing and separation of concerns. - Migrate business and data logic
Extract your business logic and data access code (e.g., Entity Framework code) into a .NET Standard class library—this library can be referenced by your ASP.NET Core 2.0 project. ReplaceSystem.Web-specific APIs: useIHttpContextAccessorinstead of staticHttpContext, and switch to ASP.NET Core'sappsettings.jsonconfiguration system instead ofWeb.config. - Refactor the UI layer
Rewrite each.aspxpage into a Razor Page (.cshtml) or MVC view. Replace WebForms server controls with native HTML elements or ASP.NET Core Tag Helpers: for example, use<input asp-for="PropertyName">instead ofasp:TextBoxFor, and<a asp-action="ActionName">instead ofasp:LinkButton. For AJAX functionality that relied onUpdatePanel, use ASP.NET Core's AJAX helpers or vanilla JavaScript/jQuery. - Configure and deploy
Migrate configuration settings fromWeb.configtoappsettings.json, and set up ASP.NET Core's dependency injection system to replace any custom dependency containers you used in WebForms. For deployment, ASP.NET Core 2.0 supports IIS hosting or self-hosting—official docs cover both scenarios in detail. - Test incrementally
Migrate and test core features first, then move to non-critical functionality. Use Visual Studio's debugging tools and ASP.NET Core's built-in logging to troubleshoot issues as you go.
If the portability analyzer you tried was cumbersome (requiring DLL uploads and hard-to-read reports), here are official, more user-friendly options:
- .NET Portability Analyzer Visual Studio Extension: This tool runs directly in Visual Studio, analyzes your project without needing to upload files, and generates clear reports highlighting unsupported APIs with suggested replacements for ASP.NET Core.
- Official WebForms-to-Core Migration Docs: Microsoft's docs include a dedicated section for WebForms migrations, complete with API mapping tables, control replacement guides, and common pitfall solutions.
内容的提问来源于stack exchange,提问作者Bhushan Gholave




