

# Modernize ASP.NET Web Forms applications on AWS
Modernize ASP.NET Web Forms applications on AWS

*Vijai Anand Ramalingam and Sreelaxmi Pai, Amazon Web Services*

## Summary


This pattern describes the steps for modernizing a legacy, monolith ASP.NET Web Forms application by porting it to ASP.NET Core on AWS.

Porting ASP.NET Web Forms applications to ASP.NET Core helps you take advantage of the performance, cost savings, and robust ecosystem of Linux. However, it can be a significant manual effort. In this pattern, the legacy application is modernized incrementally by using a phased approach, and then containerized in the AWS Cloud.

Consider a legacy, monolith application for a shopping cart. Let’s assume that it was created as an ASP.NET Web Forms application and consists of .aspx pages with a code-behind (`aspx.cs`) file. The modernization process consists of these steps:

1. Break the monolith into microservices by using the appropriate decomposition patterns. For more information, see the guide [Decomposing monoliths into microservices](https://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-decomposing-monoliths/) on the AWS Prescriptive Guidance website.

1. Port your legacy ASP.NET Web Forms (.NET Framework) application to ASP.NET Core in .NET 5 or later. In this pattern, you use Porting Assistant for .NET to scan your ASP.NET Web Forms application and identify incompatibilities with ASP.NET Core. This reduces the manual porting effort.

1. Redevelop the Web Forms UI layer by using React. This pattern doesn’t cover UI redevelopment. For instructions, see [Create a New React App](https://reactjs.org/docs/create-a-new-react-app.html) in the React documentation.

1. Redevelop the Web Forms code-behind file (business interface) as an ASP.NET Core web API. This pattern uses NDepend reports to help identify required files and dependencies.

1. Upgrade shared/common projects, such as Business Logic and Data Access, in your legacy application to .NET 5 or later by using Porting Assistant for .NET. 

1. Add AWS services to complement your application. For example, you can use [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) to monitor, store, and access your application’s logs, and [AWS Systems Manager](https://aws.amazon.com/systems-manager/) to store your application settings.

1. Containerize the modernized ASP.NET Core application. This pattern creates a Docker file that targets Linux in Visual Studio and uses Docker Desktop to test it locally. This step assumes that your legacy application is already running on an on-premises or Amazon Elastic Compute Cloud (Amazon EC2) Windows instance. For more information, see the pattern [Run an ASP.NET Core web API Docker container on an Amazon EC2 Linux instance](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/run-an-asp-net-core-web-api-docker-container-on-an-amazon-ec2-linux-instance.html).

1. Deploy the modernized ASP.NET core application to Amazon Elastic Container Service (Amazon ECS). This pattern doesn’t cover the deployment step. For instructions, see the [Amazon ECS Workshop](https://ecsworkshop.com/).

**Note**  
This pattern doesn’t cover UI development, database modernization, or container deployment steps.

## Prerequisites and limitations


**Prerequisites **
+ [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Visual Studio Code](https://code.visualstudio.com/download), downloaded and installed.
+ Access to an AWS account using the AWS Management Console and the AWS Command Line Interface (AWS CLI) version 2. (See the [instructions for configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html).)
+ The AWS Toolkit for Visual Studio (see [setup instructions](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/setup.html)).
+ Docker Desktop, [downloaded](https://www.docker.com/products/docker-desktop) and installed.
+ .NET SDK, [downloaded](https://download.visualstudio.microsoft.com/download/pr/4263dc3b-dc67-4f11-8d46-cc0ae86a232e/66782bbd04c53651f730b2e30a873f18/dotnet-sdk-5.0.203-win-x64.exe) and installed.
+ NDepend tool, [downloaded](https://www.ndepend.com/download) and installed. To install the NDepend extension for Visual Studio, run `NDepend.VisualStudioExtension.Installer` ([see instructions](https://www.ndepend.com/docs/getting-started-with-ndepend#Part1)). You can select Visual Studio 2019 or 2022, depending on your requirements. 
+ Porting Assistant for .NET, [downloaded](https://aws.amazon.com/porting-assistant-dotnet/) and installed.

## Architecture


**Modernizing the shopping cart application**

The following diagram illustrates the modernization process for a legacy ASP.NET shopping cart application.

![\[Modernizing a legacy shopping cart application\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/images/pattern-img/36cda8e6-f2cb-4f1a-b37f-fa3045cc5ba1/images/4367e259-9bb3-4eb6-a54d-1c1e2dece7d4.png)


**Target architecture**

The following diagram illustrates the architecture of the modernized shopping cart application on AWS. ASP.NET Core web APIs are deployed to an Amazon ECS cluster. Logging and configuration services are provided by Amazon CloudWatch Logs and AWS Systems Manager.

![\[Target architecture for ASP.NET Web Forms application on AWS\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/images/pattern-img/36cda8e6-f2cb-4f1a-b37f-fa3045cc5ba1/images/ed6d65ec-0dc9-43ab-ac07-1f172e089399.png)


## Tools


**AWS services**
+ [Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) – Amazon Elastic Container Service (Amazon ECS) is a highly scalable, fast container management service for running, stopping, and managing containers on a cluster. You can run your tasks and services on a serverless infrastructure that is managed by AWS Fargate. Alternatively, for more control over your infrastructure, you can run your tasks and services on a cluster of EC2 instances that you manage.
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) – Amazon CloudWatch Logs centralizes the logs from all your systems, applications, and AWS services that you use. You can view and monitor the logs, search them for specific error codes or patterns, filter them based on specific fields, or archive them securely for future analysis.
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) ─ AWS Systems Manager is an AWS service that you can use to view and control your infrastructure on AWS. Using the Systems Manager console, you can view operational data from multiple AWS services and automate operational tasks across your AWS resources. Systems Manager helps you maintain security and compliance by scanning your managed instances and reporting (or taking corrective action) on any policy violations it detects.

**Tools**
+ [Visual Studio](https://visualstudio.microsoft.com/) or [Visual Studio Code](https://code.visualstudio.com/) – Tools for building .NET applications, web APIs, and other programs.
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) – An extension for Visual Studio that helps develop, debug, and deploy .NET applications that use AWS services.
+ [Docker Desktop](https://www.docker.com/products/docker-desktop) – A tool that simplifies building and deploying containerized applications.
+ [NDepend](https://www.ndepend.com/features/) – An analyzer that monitors .NET code for dependencies, quality issues, and code changes.
+ [Porting Assistant for .NET](https://aws.amazon.com/porting-assistant-dotnet/) – An analysis tool that scans .NET code to identify incompatibilities with .NET Core and to estimate the migration effort.

## Epics


### Port your legacy application to .NET 5 or later version



| Task | Description | Skills required | 
| --- | --- | --- | 
| Upgrade your.NET Framework legacy application to .NET 5. | You can use Porting Assistant for .NET to convert your legacy ASP.NET Web Forms application to .NET 5 or later. Follow the instructions in the [Porting Assistant for .NET documentation](https://docs.aws.amazon.com/portingassistant/latest/userguide/porting-assistant-getting-started.html). | App developer | 
| Generate NDepend reports. | When you modernize your ASP.NET Web Forms application by decomposing it into microservices, you might not need all the .cs files from the legacy application. You can use NDepend to generate a report for any code-behind (.cs) file, to get all the callers and callees. This report helps you identify and use only the required files in your microservices.After you install NDepend (see the [Prerequisites ](#modernize-asp-net-web-forms-applications-on-aws-prereqs)section), open the solution (.sln file) for your legacy application in Visual Studio and follow these steps:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)This process generates a report for the code-behind file that lists all callers and callees. For more information about the dependency graph, see the [NDepend documentation](https://www.ndepend.com/docs/visual-studio-dependency-graph). | App developer | 
| Create a new .NET 5 solution. | To create a new .NET 5 (or later) structure for your modernized ASP.NET Core web APIs:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)For more information about creating projects and solutions, see the [Visual Studio documentation](https://docs.microsoft.com/en-us/visualstudio/ide/creating-solutions-and-projects).As you build the solution and verify functionality, you might identify several additional files to be added to the solution, in addition to the files that NDepend identified. | App developer | 

### Update your application code



| Task | Description | Skills required | 
| --- | --- | --- | 
| Implement web APIs with ASP.NET Core. | Let’s assume that one of the microservices that you identified in your legacy monolith shopping cart application is *Products*. You created a new ASP.NET Core web API project for *Products* in the previous epic. In this step, you identify and modernize all the web forms (.aspx pages) that are related to *Products*. Let’s assume that *Products* consists of four web forms, as illustrated earlier in the [Architecture](#modernize-asp-net-web-forms-applications-on-aws-architecture) section:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)You should analyze each web form, identify all the requests that are sent to the database to perform some logic, and get responses. You can implement each request as a web API endpoint. Given its web forms, *Products* can have the following possible endpoints:[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)As mentioned previously, you can also reuse all the other projects that you upgraded to .NET 5, including Business Logic, Data Access, and shared/common projects. | App developer | 
| Configure Amazon CloudWatch Logs. | You can use [Amazon CloudWatch Logs](http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) to monitor, store, and access your application’s logs. You can log data into Amazon CloudWatch Logs by using an AWS SDK. You can also integrate .NET applications with CloudWatch Logs by using popular .NET logging frameworks such as [NLog](https://www.nuget.org/packages/AWS.Logger.NLog/), [Log4Net](https://www.nuget.org/packages/AWS.Logger.Log4net/), and [ASP.NET Core logging framework](https://www.nuget.org/packages/AWS.Logger.AspNetCore/).For more information about this step, see the blog post [Amazon CloudWatch Logs and .NET Logging Frameworks](https://aws.amazon.com/blogs/developer/amazon-cloudwatch-logs-and-net-logging-frameworks/). | App developer | 
| Configure AWS Systems Manager Parameter Store. | You can use [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html) to store application settings such as connection strings separately from your application’s code. The NuGet package [Amazon.Extensions.Configuration.SystemsManager](https://www.nuget.org/packages/Amazon.Extensions.Configuration.SystemsManager/) simplifies how your application loads these settings from the AWS Systems Manager Parameter Store into the .NET Core configuration system. For more information about this step, see the blog post [.NET Core configuration provider for AWS Systems Manager](https://aws.amazon.com/blogs/developer/net-core-configuration-provider-for-aws-systems-manager/). | App developer | 

### Add authentication and authorization



| Task | Description | Skills required | 
| --- | --- | --- | 
| Use a shared cookie for authentication. | Modernizing a legacy monolith application is an iterative process and requires the monolith and its modernized version to co-exist. You can use a shared cookie to achieve seamless authentication between the two versions. The legacy ASP.NET application continues to validate user credentials and issues the cookie while the modernized ASP.NET Core application validates the cookie. For instructions and sample code, see the [sample GitHub project](https://github.com/aws-samples/dotnet-share-auth-cookie-between-monolith-and-modernized-apps). | App developer | 

### Build and run the container locally



| Task | Description | Skills required | 
| --- | --- | --- | 
| Create a Docker image by using Visual Studio. | In this step, you create a Docker file by using the Visual Studio for .NET Core web API.[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)Visual Studio creates a Docker file for your project. For a sample Docker file, see [Visual Studio Container Tools for Docker](https://docs.microsoft.com/en-us/visualstudio/containers/overview) on the Microsoft website. | App developer | 
| Build and run the container by using Docker Desktop. | Now you can build, create and run the container in Docker Desktop.[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html) | App developer | 

## Related resources

+ [Run an ASP.NET Core web API Docker container on an Amazon EC2 Linux instance](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/run-an-asp-net-core-web-api-docker-container-on-an-amazon-ec2-linux-instance.html) (AWS Prescriptive Guidance)
+ [Amazon ECS Workshop](https://ecsworkshop.com/)
+ [Perform ECS blue/green deployments through CodeDeploy using AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html) (AWS CloudFormation documentation)
+ [Getting started with NDepend](https://www.ndepend.com/docs/getting-started-with-ndepend) (NDepend documentation)
+ [Porting Assistant for .NET](https://aws.amazon.com/porting-assistant-dotnet/)

## Additional information


The following tables provide examples of sample projects for a legacy shopping cart application and the equivalent projects in your modernized ASP.NET Core application.

**Legacy solution:**


| 
| 
| Project name | Project template | Target framework | 
| --- |--- |--- |
| Business Interface  | Class Library  | .NET Framework  | 
| BusinessLogic  | Class Library  | .NET Framework  | 
| WebApplication  | ASP.NET Framework Web Application  | .NET Framework  | 
| UnitTests  | NUnit Test Project  | .NET Framework  | 
| Shared ->Common  | Class Library  | .NET Framework  | 
| Shared ->Framework  | Class Library  | .NET Framework  | 

**New solution:**


| 
| 
| Project name | Project template | Target framework | 
| --- |--- |--- |
| BusinessLogic  | Class Library  | .NET 5.0  | 
| <WebAPI>  | ASP.NET Core Web API  | .NET 5.0  | 
| <WebAPI>.UnitTests  | NUnit 3 Test Project  | .NET 5.0  | 
| Shared ->Common  | Class Library  | .NET 5.0  | 
| Shared ->Framework  | Class Library  | .NET 5.0  | 