You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

ASP.NET WebForms(ASPX)项目迁移至ASP.NET Core 2.0的可行性与方案咨询

Hey there, let's tackle your questions clearly and based on official Microsoft guidelines:

1. Confirmation: ASPX Support in ASP.NET Core 2.0

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).

2. Official Step-by-Step Migration Guide from ASP.NET WebForms to ASP.NET Core 2.0

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 (like GridView, UpdatePanel), dependencies on System.Web APIs, 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. Replace System.Web-specific APIs: use IHttpContextAccessor instead of static HttpContext, and switch to ASP.NET Core's appsettings.json configuration system instead of Web.config.
  • Refactor the UI layer
    Rewrite each .aspx page 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 of asp:TextBoxFor, and <a asp-action="ActionName"> instead of asp:LinkButton. For AJAX functionality that relied on UpdatePanel, use ASP.NET Core's AJAX helpers or vanilla JavaScript/jQuery.
  • Configure and deploy
    Migrate configuration settings from Web.config to appsettings.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.
3. Better Alternatives to the Portability Tool You Used

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

火山引擎 最新活动