Deploying ASP.NET Web Forms applications on AWS - AWS Prescriptive Guidance

Deploying ASP.NET Web Forms applications on AWS

Managing NuGet packages

NuGet is a repository that contains and manages code packages for .NET. An application can have two types of NuGet packages installed: publicly available packages from nuget.org or custom-built packages that are published to an internal repository. Pulling down packages from nuget.org requires that the instances building the application have outbound internet access. For some users, internet access might not be desirable because of security concerns or network restrictions.

To solve this issue, you can provision a managed artifact (NuGet) repository to download packages from external sources such as nuget.org. You can use AWS CodeArtifact, which is a fully managed artifact repository service, as a NuGet package repository. For more information, see the AWS blog post Using NuGet with AWS CodeArtifact. Other popular third-party options include Nexus and Artifactory. This approach allows you to cache publicly available packages within your private repository and reduces the need for direct internet access during the build process. If you want more control over which packages can be downloaded, you can disable external access. In this case, developers will have to push both their own NuGet packages and any other third-party packages they need to the repository.

To configure your application to use the NuGet package repository, create a NuGet.config file in the project root or solution root directory. This file specifies the package sources that NuGet should use when restoring packages. The following example shows how to configure the NuGet.config file to use CodeArtifact:

<?xml version="1.0" encoding="utf-8"?> <configuration> <packageRestore> <!-- Allow NuGet to download missing packages --> <add key="enabled" value="True" /> <!-- Automatically check for missing packages during build in Visual Studio --> <add key="automatic" value="True" /> </packageRestore> <packageSources> <add key="MyRepo" value="https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/nuget/my_repo/v3/index.json" /> </packageSources> </configuration>

In this example, replace https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/nuget/my_repo/v3/index.json with the actual URL of your CodeArtifact repository. You can find this URL on the CodeArtifact console or by running the aws codeartifact get-repository-endpoint command.

Important
  • Configuring the NuGet.config file affects all projects within the same directory structure. If you want to use different package sources for different projects, create separate NuGet.config files for each project or solution.

  • Make sure that the instances building the application have the necessary permissions and network access to connect to the NuGet package repository (such as CodeArtifact). For more information about obtaining credentials, see Use CodeArtifact with the nuget or dotnet CLI in the CodeArtifact documentation.

Building an application

When you migrate legacy ASP.NET Web Forms applications to AWS, you continue using the Microsoft Build Engine (MSBuild) as the central tool for building the applications. MSBuild is typically bundled with Visual Studio, but you can download and use the standalone MSBuild executable from Microsoft without installing Visual Studio. This approach is particularly useful when you build your Web Forms application on AWS, where you can use Windows instances or Docker containers with MSBuild installed.

There are two main steps required to build an ASP.NET Web Forms application: restoring the NuGet packages and building the application. The specifics of how these steps are performed might vary depending on the CI/CD tool you choose to use. For example, if you use AWS CodeBuild, the build process is executed inside a Docker container.

Restore NuGet packages

Before you build your application, you must restore the NuGet packages required by the project. You can do this by using either MSBuild or NuGet Command Line Interface (CLI) commands, executed in the project's root directory.

Using MSBuild:

msbuild -t:restore

Using NuGet CLI:

nuget restore

Build using MSBuild

After you restore the NuGet packages, you can proceed with the main build command that produces the deployment artifacts. The command typically specifies the project file, the build configuration (for example, Release), and the output directory for the built artifacts.

msbuild <ProjectName>.csproj /p:Configuration=Release /p:OutDir=<OutDir>

For more information about MSBuild options, see MSBuild command-line reference in the Microsoft documentation.

For more information about building an ASP.NET application with AWS CodeBuild, see the AWS blog post Creating CI/CD pipelines for ASP.NET 4.x with AWS CodePipeline and AWS Elastic Beanstalk.

Deploying an application

After you build your Web Forms application, you deploy the artifacts to the target environment on AWS. In most scenarios, you can zip and upload the built artifacts to an Amazon Simple Storage Service (Amazon S3) bucket for easy distribution and deployment. For instructions, see the Amazon S3 documentation.

There are two main options for deploying the artifacts to an Amazon EC2 instance: manual and automated.

Manual deployment

This option involves using the EC2 instance user data to include scripts that will perform the following tasks:

  • Install Internet Information Services (IIS)

  • Pull and unpack the build artifacts from the Amazon S3 bucket

  • Create and configure the IIS application

Although this approach provides flexibility, it requires manual intervention and might become challenging to manage as your application scales or if it undergoes frequent updates.

Automated deployment

The recommended approach is to use AWS CodeDeploy for automated and repeatable deployments. CodeDeploy seamlessly integrates with other AWS services such as AWS CodeBuild and AWS CodePipeline, so you can create a complete CI/CD pipeline for your ASP.NET Web Forms application. With CodeDeploy, you can define deployment strategies such as rolling and blue/green updates to ensure minimal downtime and smooth transitions between application versions.

For more information and examples on setting up CI/CD pipelines for ASP.NET Web Forms applications by using CodePipeline, CodeBuild, and CodeDeploy, see the AWS blog post Creating CI/CD pipelines for ASP.NET 4.x with AWS CodePipeline and AWS Elastic Beanstalk.

By using AWS services such as CodeBuild, CodeDeploy, and CodePipeline, you can streamline the build and deployment processes for your migrated ASP.NET Web Forms applications, and ensure consistent and reliable deployments to AWS infrastructure.

For additional information about automated deployments, see the AWS blog post Generating CI/CD Pipelines for Containerized ASP.NET Applications using AWS App2Container and the information about building a CI/CD pipeline for legacy .NET Framework applications in AWS re:Post.