ASP.NET MVC 5 runs only on .NET Framework and only under IIS. Moving such an application to ASP.NET Core MVC looks like the easiest migration there is: controllers stay controllers, Razor stays Razor, and most of the code compiles after changing a few namespaces. That is exactly why it is risky. The code translates almost word for word, and the defaults underneath it are different.
This case ports a small server-rendered application and checks the result the only way that counts for a web application: by what a browser receives. The code is on GitHub: chudovo/application-modernization, case 08.
At a glance
| Before | After | |
|---|---|---|
| Framework | ASP.NET MVC 5.3, .NET Framework 4.8 | ASP.NET Core MVC, .NET 10 |
| Host | IIS or IIS Express, Windows | Kestrel, any operating system |
| Configuration | Web.config, Global.asax | Program.cs |
| Views | HTML helpers | tag helpers |
| Part of the layout | child action | view component |
| Sign-in | forms authentication | cookie authentication |
| Contract checks passing | 21 of 21 | 21 of 21, after 11 failures in the first version |
The application
It takes registrations for seminars. Visitors see a list of courses with prices and dates, open a course, fill in a form and get a confirmation. An administrator signs in and sees the registrations. A partner site reads the course list as JSON. It is a German application, so prices look like 1.249,50 € and users type amounts with a decimal comma. That detail turns out to matter more than anything else.
Step 1: a contract in a browser’s terms
The contract is 21 checks that know only HTTP and HTML. A small test browser keeps cookies, parses pages, and submits forms with their hidden fields, anti-forgery token included. It reads the text a user would see, so differences in markup that a browser hides do not count.
[Theory]
[InlineData("1500,00", "1.500,00 EUR")] // a decimal comma, the German way
[InlineData("750,5", "750,50 EUR")]
[InlineData("2000", "2.000,00 EUR")]
public async Task Amounts_are_read_the_way_german_users_type_them(string typed, string shown)
{
// Loads the form, fills it in, posts it with its hidden fields, like a browser.
var posted = await RegisterAsync(Registration(budget: typed));
Assert.Equal(HttpStatusCode.Found, posted.Status);
Assert.Equal(shown, (await _browser.GetAsync(posted.Location!)).Text("#budget"));
}
The same test project runs against the old application under IIS Express on Windows and against the new one under Kestrel on Linux. Running it against the old application first was useful on its own: two of my assumptions about the old behaviour were wrong, and the contract was corrected to what the application really does.
Step 2: the straightforward port
The first version of the new application was a direct translation, done the way most ports are done: same controllers, the same views rewritten with tag helpers, default settings.
@* ASP.NET MVC 5: HTML helpers, and a child action rendered inside the layout *@
@using (Html.BeginForm("Create", "Registrations", FormMethod.Post, new { id = "registration" }))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(m => m.Name)
@Html.ValidationMessageFor(m => m.Name)
}
@Html.Action("Summary", "Registrations")
@* ASP.NET Core MVC: tag helpers, and a view component *@
<form id="registration" asp-action="Create" method="post">
<input asp-for="Name" type="text" />
<span asp-validation-for="Name"></span>
</form>
<vc:registration-summary />
It compiled, started, and looked right at a glance. Against the contract, 11 of 21 checks failed. There were three causes.
Cause 1: one line of Web.config
<!-- Web.config of the old application. One line, and every price, date and typed number is German. -->
<globalization culture="de-DE" uiCulture="de-DE" />
ASP.NET Core has no equivalent setting. An application without it uses the culture of the server, and a Linux container has none: it runs with the invariant culture.
| Old application | Straightforward port | |
|---|---|---|
| Price on the home page | 1.249,50 € | ¤1,249.50 |
| User types a budget of 750,5 | stored as 750.50 | stored as 7505.00, no error |
| User types 1500,00 | stored as 1500.00 | refused as out of range |
The first row is ugly and somebody would notice it on the first day. The middle row is the dangerous one. A valid German amount is accepted without complaint and stored ten times too high, because the comma is read as a thousands separator. Nothing crashes, nothing is logged.
// ASP.NET Core has no such setting. Without this block the server's own culture is used,
// which in a Linux container is the invariant one.
var german = new CultureInfo("de-DE");
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(german),
SupportedCultures = [german],
SupportedUICultures = [german],
RequestCultureProviders = [], // the old application ignored the browser's language, so does this one
});
Cause 2: the JSON changed shape
The partner site reads the course list from an action that returns JSON. The call in the controller is the same in both frameworks. The output is not:
// ASP.NET MVC 5, Json(found, JsonRequestBehavior.AllowGet):
[{"Id":2,"Title":"Größere Refactorings planen","Price":890.00,"Start":"\/Date(1770109200000)\/"}]
// ASP.NET Core, Json(found) with default settings:
[{"id":2,"title":"Gr\u00F6\u00DFere Refactorings planen","price":890.00,"start":"2026-02-03T09:00:00Z"}]
// Configured to the old shape:
builder.Services.AddControllersWithViews().AddJsonOptions(json =>
{
json.JsonSerializerOptions.PropertyNamingPolicy = null;
json.JsonSerializerOptions.Converters.Add(new LegacyDateConverter()); // writes "/Date(milliseconds)/"
});
Property names and the date format are part of what the partner’s script depends on. Nobody on the partner’s side will be asked before the release, so the new application writes the old shape.
Cause 3: decimals are read more generously
With the culture fixed, 2 of 21 checks still failed. ASP.NET MVC 5 accepts a decimal separator in a number and nothing else. ASP.NET Core also accepts thousands separators. On a German system the point is the thousands separator:
| User types | Old application | ASP.NET Core with German culture |
|---|---|---|
| 750.50 | validation message | stored as 75050.00, no error |
| 1.500,00 | validation message | stored as 1500.00 |
Accepting 1.500,00 is arguably an improvement. Turning 750.50 into seventy-five thousand is not, and the two come together. Someone who copies an amount from an English spreadsheet gets a hundred times the budget. The new application reads decimals the way the old one did:
public Task BindModelAsync(ModelBindingContext context)
{
var value = context.ValueProvider.GetValue(context.ModelName);
if (value == ValueProviderResult.None) return Task.CompletedTask;
context.ModelState.SetModelValue(context.ModelName, value);
var text = value.FirstValue;
if (string.IsNullOrWhiteSpace(text)) return Task.CompletedTask;
// NumberStyles.Float: a decimal separator of the current culture, no thousands separator. As MVC 5 did.
if (decimal.TryParse(text, NumberStyles.Float, CultureInfo.CurrentCulture, out var number))
context.Result = ModelBindingResult.Success(number);
else
context.ModelState.TryAddModelError(context.ModelName, $"The value '{text}' is not valid for {context.ModelMetadata.GetDisplayName()}.");
return Task.CompletedTask;
}
Whether to relax that rule is a product decision. It should be taken on purpose and later, not arrive as a side effect of a framework change.
What translated without surprises
- routing, including addresses in another letter case and with a trailing slash
- validation with data annotations, the messages, and the attributes that client-side validation reads
- HTML encoding of data that contains markup
- the redirect to the login page and back, and the refusal to redirect to another site after sign-in
- the notice that survives exactly one redirect (TempData)
- anti-forgery protection
- the child action in the layout, rewritten as a view component
That is most of the application. The framework parts that people expect to be hard were mechanical. The failures all came from settings that are not in the C# code at all.
What is verified, and what is not
| Check | Result |
|---|---|
| Contract against ASP.NET MVC 5, Windows, IIS Express | 21 / 21 |
| Contract against ASP.NET Core MVC, Linux, Kestrel | 21 / 21 |
- Not the bytes. The contract compares what a browser shows. The raw output differs where a browser does not care: MVC 5 writes ü as ü, ASP.NET Core as ü, and in JSON the old serializer writes ü as it is while the new one escapes it. A client that reads the response as plain text would notice.
- Signed-in users are signed out once. The authentication cookie has another name and format. Forms that are open in a browser at the moment of the switch are refused once, because their anti-forgery token is from the old application.
- No JavaScript runs in the tests. The attributes for client-side validation are checked, the scripts are not executed.
- Features this application does not use: bundling, areas, session state, output caching, HTTP modules, Windows authentication. Each has its own migration path.
One thing went wrong on the old side. The Razor views are UTF-8 files without a byte order mark, and under IIS Express the page title came out as Kursübersicht. ASP.NET read the files in the system code page. Visual Studio hides this by saving views with a mark; a file encoding setting in Web.config fixes it.
Run it yourself
The new application and the contract need only the .NET 10 SDK:
dotnet run --project after/src/Seminars.Web --urls http://localhost:5080
dotnet test contract
Running the old application needs Windows with IIS Express. The command is in the README of the case.
When this path fits
This is the direct route for an application that is server-rendered, works, and has to leave .NET Framework: keep the architecture, replace the framework, and prove the result against the old behaviour. It is rarely the place to redesign anything at the same time. How it fits into a larger plan is covered in the application modernization strategy guide. Related cases move a Web API from .NET Framework to .NET 10 and replace Entity Framework 6 with EF Core.
If you need a team for a migration like this, see our comparison of top .NET modernization companies.