Error when migrating ASP.NET 4 project to .NET Core #2
|
I’m in the process of refactoring an existing ASP.NET 4 (MVC/Web API) application to .NET Core. After updating the project structure and dependencies, I’m running into errors during build/runtime. Steps to Reproduce: Migrate ASP.NET 4 project to .NET Core 6 Update csproj and NuGet dependencies Try to run the app with dotnet run Expected Behavior: Actual Behavior:
Or runtime error:
Environment: Original Framework: .NET Framework 4.7.2 Target: .NET 6 OS: Windows 11 Additional Context: |
Replies: 2 comments 1 reply
|
When you move from ASP.NET 4 to .NET Core, you can’t use System.Web anymore. Instead, you swap things out for Core’s way of doing it. For example, instead of Web.config, you use an appsettings.json file and read it with the built-in configuration system. If you were using HttpModules or Global.asax, you switch to middleware in Program.cs or Startup.cs. And if you were using FormsAuthentication, you’d move over to ASP.NET Core Identity or JWT. So it’s not about fixing the error directly; it’s about replacing the old APIs with the Core equivalents step by step. |
|
When migrating, I hit errors because System.Web.Configuration.WebConfigurationManager doesn’t exist in .NET Core. |
That class isn’t in .NET Core. You need to replace it with the configuration API.
Use appsettings.json and read values through Microsoft.Extensions.Configuration instead of Web.config.