title
stringlengths
3
46
content
stringlengths
0
1.6k
2:38
2:39
Besides these, the Instance Details are as follows:
2:40
2:41
Name: As you can see, the web app name is the URL that your solution will assume after its creation. The name must be globally unique and is checked to ensure it is available.
2:42
Publish: This parameter indicates whether the web app will be delivered directly, a static web app, or whether it is going to use Docker technology to publish content. Docker will be discussed in more detail in Chapter 11, Applying a Microservice Architecture to Your Enterprise Application. If you opt for the Docker container publication, you will be able to configure the Image Source, Access Type, and Image and tag information to have it deployed to the web app.
2:43
Runtime stack: This option is obviously only available when you decide to deliver code directly. You could define stacks for .NET, Go, Java, Node.js, PHP, Python, and Ruby.
2:44
Operating System: This is the option for defining the OS that will host the web app. Both Windows and Linux may be used for .NET projects in the newest versions.
2:45
Region: You may consider where you want to deploy your application; Azure has many different data centers all over the world.
2:46
Pricing Plans: This is where you define the hardware plan that is used to handle the web app and the region of the servers. This choice defines application scalability, performance, and costs.
2:47
Zone redundancy: Starting with premium pricing plans, you will be able to activate zone redundancy, which will increase the availability of the solution.
2:48
Deployment: It is possible to define the GitHub repository that is responsible for continuously deploying the application.
2:49
Networking: You may select the network behavior of the application according to its requirements and proposal.
2:50
Monitoring: This is a useful Azure toolset for monitoring and troubleshooting web apps. In this section, you can enable Application Insights. It is always recommended that you keep the same regions for the different components of your solution since this will save costs in terms of traffic exchange from one data center to another.
2:51
2:52
Once you have created your web app, this application may be scaled in two conceptually different ways: vertically (scale up) and horizontally (scale out). Both are available in the web app settings, as you can see in the following screenshot:
2:53
2:54
Figure 2.3: Scaling options for web apps
2:55
Let us check out the two types of scaling.
2:56
Vertical scaling (scaling up)
2:57
Scaling up means changing the specification of the hardware that will host your application. In Azure, you have the opportunity to start with free, shared hardware and move to an isolated machine in a few clicks. The following screenshot shows the user interface for scaling up a web app:
2:58
2:59
Figure 2.4: Vertical scaling options
2:60
By choosing one of the options provided, you can select more powerful hardware (machines with more CPUs, storage, and RAM). Monitoring your application and its App Service plan will guide you on how to decide the best infrastructure for running your solution. It will also offer key insights, such as possible CPU, memory, and I/O bottlenecks.
2:61
Horizontal scaling (scaling out)
2:62
Scaling out means splitting requests between more servers and using the same capacity instead of using more powerful machines. The load on all the servers is automatically balanced by the Azure infrastructure. This solution is advised when the overall load may change considerably in the future since horizontal scaling can automatically adapt to a given load. The following screenshot shows an automatic Scale out strategy defined by two simple rules, triggered by CPU usage:
2:63
2:64
Figure 2.5: Horizontal scaling sample
2:65
It is worth highlighting that you can choose to have a hardcoded instance count or implement rules for automatic scale in/out.
2:66
A complete description of all the available autoscale rules is beyond the scope of this book. However, they are quite self-explanatory, and the Further reading section contains links to the full documentation.
2:67
The Scale out feature is only available in paid service plans.
2:68
In general, horizontal scaling is a way to guarantee availability in an application even with several simultaneous accesses. For sure, its use is not the only way to keep a system available, but it does help.
2:69
Creating a scalable web app with .NET 8
2:70
Among all the available frameworks for implementing web apps, running web apps with ASP.NET Core in .NET 8 ensures good performance, together with low production and maintenance costs. The union of C#, a strongly typed and advanced general-purpose language, and continuous performance improvements achieved in ASP.NET Core distinguish this option as one of the best for enterprise development.
2:71
The steps in this section will guide you through the creation of an ASP.NET Core Runtime 8-based web app. All the steps are quite simple, but some details require particular attention.
2:72
It is worth mentioning that .NET 8 gives you the opportunity to develop for any platform – desktops (WPF, Windows Forms, and UWP), web (ASP.NET), cloud (Azure), mobile (Xamarin), gaming (Unity), IoT (ARM32 and ARM64), or AI (ML.NET and .NET for Apache Spark). So, the recommendation from now on is to only use .NET 8. In this scenario, you can run your web app on either Windows servers or cheaper Linux servers.
2:73
Nowadays, Microsoft recommends classic .NET, just in case the features you need are not available in .NET Core/5+ or you are deploying your web app in an environment that does not support .NET Core. In any other case, you should prefer .NET Core/5+ because it allows you to do the following:
2:74
2:75
Run your web app in Windows, Linux, macOS, or Docker containers
2:76
Design your solution with microservices
2:77
Have high-performance and scalable systems
2:78
2:79
Containers and microservices will be covered in Chapter 11, Applying a Microservice Architecture to Your Enterprise Application. There, you will get a better understanding of the advantages of these technologies. For now, it is enough to say that .NET 8 and microservices were designed for performance and scalability, which is why you should prefer .NET 8 in all your new projects. Besides, .NET 8 is guaranteed by Microsoft as a Long Term Support version, which means three years of patches and free support.
2:80
2:81
Figure 2.6: .NET 8 support policy
2:82
The following procedure will show you how to create an ASP.NET Core web app in Visual Studio 2022 with .NET 8:
2:83
2:84
As soon as you start VS 2022, you will be able to click on Create a new project.
2:85
Once you select ASP.NET Core Web App, you will be directed to a screen where you will be asked to set up Project name, Location, and Solution name:
2:86
2:87
2:88
Figure 2.7: Creating an ASP.NET Core web application
2:89
2:90
After that, you will be able to select the .NET version to use. Select .NET 8.0 to get the most advanced and up-to-date platform.
2:91
Click Create to create your ASP.NET Core 8 web app.
2:92
Now that you are done with adding the basic details, you can connect your web app project to your Azure account and publish it.
2:93
If you right-click the project you created in Solution Explorer, you have the option to Publish.
2:94
You will find different targets in terms of where to publish your web app. Select Azure as the target:
2:95
2:96
2:97
Figure 2.8: Targeting Azure to publish the app
2:98
2:99
Then, you will be able to decide the specific target to publish. Select Azure App Service (Windows) for this demo.
2:100
You may be required to define your Microsoft Account credentials at this time. This is because there is full integration between Visual Studio and Azure. This gives you the opportunity to view all the resources you created in the Azure portal in your development environment.
2:101
2:102
2:103
Figure 2.9: Integration between Visual Studio and Azure
2:104
2:105
If you want to create a new web app using Visual Studio, make sure to select the Free Size tier of pricing during the App Service creation process so that this does not incur any costs:
2:106
2:107
2:108
Figure 2.10: Creating a New Hosting Plan
2:109
2:110
The usual way to deploy using Visual Studio is by selecting Publish Profile, which generates a .pubxml file, which is a Visual Studio publish profile. In this case, you currently have two modes for deployment.
2:111
The first, Framework-dependent, will require a web app configured with the target framework. The second, Self-contained, will not need this feature since the binaries of the framework will be published together with the application. Once the file is created and the options are selected, you just click on the Publish button, and the process will start:
2:112
2:113
Figure 2.11: Publish profile web deploy
2:114
2:115
2:116
It is worth mentioning that to publish ASP.NET Preview versions in Framework-dependent mode, you must add an extension in the web app setup panel in the Azure portal, as shown in the following screenshot. However, consider using Self-contained mode, especially when you are under preview versions and using Windows apps:
2:117
2:118
2:119
Figure 2.12: Adding extensions in Azure App Service
2:120
2:121
For more information on deploying ASP.NET Core 8.0 to Azure App Service, please refer to the following link: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/?view=aspnetcore-8.0&tabs=visual-studio.
2:122
2:123
Although publishing using Visual Studio 2022 may be considered a good option for demonstration, in the real world, it is almost impossible to keep your publishing strategy using it. For this reason, you might consider using a CI/CD flow based on GitHub Actions, which automatically enables deployment on the code being pushed to a GitHub repo. It is worth mentioning that you must be connected to a GitHub repo to access this new function. Let us use this new feature for this demonstration. We will discuss it in more depth in Chapter 8, Understanding DevOps Principles and CI/CD.
2:124
2:125
Figure 2.13: Deploying a web app using GitHub actions
2:126
2:127
Once you have pushed your code, you can go to the GitHub Actions pane and select the way you want to deploy the web app.
2:128
For this second demo, you can select Deploy a .NET Core app to an Azure Web App. With this option, you will have a YAML file created with all the instructions needed to connect your code to the web app.
2:129
2:130
Figure 2.14: YAML file used to deploy the application
2:131
2:132
Depending on the web app you want to deploy, you will need a different script. These scripts are documented at https://github.com/Azure/webapps-deploy.
2:133
2:134
2:135
2:136
Once you have set the correct script, you will be able to check the execution of the GitHub Action:
2:137