A Developer's Guide to .NET in Azure: Build quick, scalable cloud-native applications and microservices with .NET 6.0 and Azure
()
About this ebook
A Developer’s Guide to .NET in Azure helps you embark on a transformative journey through Microsoft Azure that is tailored to .NET developers. This book is a curated compendium that’ll enable you to master the creation of resilient, scalable, and highly available applications.
The book is divided into four parts, with Part 1 demystifying Azure for you and emphasizing the portal's utility and seamless integration. The chapters in this section help you configure your workspace for optimal Azure synergy. You’ll then move on to Part 2, where you’ll explore serverless computing, microservices, containerization, Dapr, and Azure Kubernetes Service for scalability, and build pragmatic, cost-effective applications using Azure Functions and Container apps. Part 3 delves into data and storage, showing you how to utilize Azure Blob Storage for unstructured data, Azure SQL Database for structured data, and Azure Cosmos DB for document-oriented data. The final part teaches you about messaging and security, utilizing Azure App Configuration, Event Hubs, Service Bus, Key Vault, and Azure AD B2C for robust, secure applications.
By the end of this book, you’ll have mastered Azure's responsive infrastructure for exceptional applications.
Related to A Developer's Guide to .NET in Azure
Related ebooks
Hands-On Azure for Developers: Implement rich Azure PaaS ecosystems using containers, serverless services, and storage solutions Rating: 0 out of 5 stars0 ratingsAzure for Developers.: Implement rich Azure PaaS ecosystems using containers, serverless services, and storage solutions Rating: 0 out of 5 stars0 ratingsThe Azure Cloud Native Architecture Mapbook: Explore Microsoft Cloud's infrastructure, application, data, and security architecture Rating: 0 out of 5 stars0 ratingsAzure Containers Explained: Leverage Azure container technologies for effective application migration and deployment Rating: 0 out of 5 stars0 ratingsAzure Stack Hub Demystified: Building hybrid cloud, IaaS, and PaaS solutions Rating: 0 out of 5 stars0 ratingsAzure for .NET Core Developers: Implementing Microsoft Azure Solutions Using .NET Core Framework Rating: 0 out of 5 stars0 ratingsAzure Integration Guide for Business: Master effective architecture strategies for business innovation Rating: 0 out of 5 stars0 ratingsAccelerating DevSecOps on AWS: Create secure CI/CD pipelines using Chaos and AIOps Rating: 0 out of 5 stars0 ratingsHands-On Networking with Azure: Build large-scale, real-world apps using Azure networking solutions Rating: 0 out of 5 stars0 ratingsArchitecting Cloud-Native Serverless Solutions: Design, build, and operate serverless solutions on cloud and open source platforms Rating: 0 out of 5 stars0 ratingsImplementing Hybrid Cloud with Azure Arc: Explore the new-generation hybrid cloud and learn how to build Azure Arc-enabled solutions Rating: 0 out of 5 stars0 ratingsAzure Architecture Explained: A comprehensive guide to building effective cloud solutions Rating: 0 out of 5 stars0 ratingsLearn Microsoft Azure: Build, manage, and scale cloud applications using the Azure ecosystem Rating: 0 out of 5 stars0 ratingsIntegrating Serverless Architecture: Using Azure Functions, Cosmos DB, and SignalR Service Rating: 0 out of 5 stars0 ratingsAWS CDK in Practice: Unleash the power of ordinary coding and streamline complex cloud applications on AWS Rating: 0 out of 5 stars0 ratingsLearn Azure Administration: Explore cloud administration concepts with networking, computing, storage, and identity management Rating: 0 out of 5 stars0 ratingsDemystifying the Azure Well-Architected Framework: Guiding Principles and Design Best Practices for Azure Workloads Rating: 0 out of 5 stars0 ratingsOptimizing Microsoft Azure Workloads: Leverage the Well-Architected Framework to boost performance, scalability, and cost efficiency Rating: 0 out of 5 stars0 ratingsAzure Active Directory for Secure Application Development: Use modern authentication techniques to secure applications in Azure Rating: 0 out of 5 stars0 ratingsHybrid Cloud for Developers: Develop and deploy cost-effective applications on the AWS and OpenStack platforms with ease Rating: 0 out of 5 stars0 ratings
Computers For You
The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution Rating: 4 out of 5 stars4/5The Invisible Rainbow: A History of Electricity and Life Rating: 5 out of 5 stars5/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5Standard Deviations: Flawed Assumptions, Tortured Data, and Other Ways to Lie with Statistics Rating: 4 out of 5 stars4/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5Deep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 5 out of 5 stars5/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsHow to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5Slenderman: Online Obsession, Mental Illness, and the Violent Crime of Two Midwestern Girls Rating: 4 out of 5 stars4/5Computer Science I Essentials Rating: 5 out of 5 stars5/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Uncanny Valley: A Memoir Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsCompTia Security 701: Fundamentals of Security Rating: 0 out of 5 stars0 ratingsPeople Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5CompTIA Security+ Get Certified Get Ahead: SY0-701 Study Guide Rating: 5 out of 5 stars5/5Alan Turing: The Enigma: The Book That Inspired the Film The Imitation Game - Updated Edition Rating: 4 out of 5 stars4/5The Data Warehouse Toolkit: The Definitive Guide to Dimensional Modeling Rating: 0 out of 5 stars0 ratingsCreating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5
Reviews for A Developer's Guide to .NET in Azure
0 ratings0 reviews
Book preview
A Developer's Guide to .NET in Azure - Anuraj Parameswaran
A Developer’s Guide to .NET in Azure
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Preet Ahuja
Senior Content Development Editor: Adrija Mitra
Technical Editor: Arjun Varma
Copy Editor: Safis Editing
Project Coordinator: Ashwin Dinesh Kharwa
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Production Designer: Jyoti Chauhan
Marketing Coordinator: Rohan Dobhal
First published: October 2023
Production reference: 1220923
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.
ISBN 978-1-83763-301-2
www.packtpub.com
To my beloved family, consisting of Sreeja, Sidhardh, and Sivaardra, and to my parents, Parameswaran Namboothiri and Saraswathi, I dedicate this book with heartfelt gratitude. Your unwavering support, guidance, and boundless love have been the driving force behind my journey. Thank you for being a constant source of inspiration in my life.
– Anuraj Parameswaran
To my amazing mother and sister, thank you for your unwavering support and resilience. You have inspired me to overcome challenges and reach for greatness. Your love and strength are my endless source of inspiration. I am forever grateful.
– Tamir AlBalkhi
Contributors
About the authors
Anuraj Parameswaran is a seasoned IT expert with over 19 years of experience, starting in 2004, with a strong focus on Azure and .NET technologies. Currently serving as the Chief Technology Officer (CTO) of Socxo Solutions Pvt. Ltd., he has received seven prestigious Microsoft MVP awards. Anuraj actively participates in mentoring programs, delivers speeches at various events, and contributes extensively to both Microsoft and Azure communities. His commitment to sharing knowledge and embracing lifelong learning is exemplified by his involvement as a technical reviewer for Packt books.
I am deeply grateful to my colleagues at Socxo Solutions Pvt. Ltd. for their invaluable support and unwavering encouragement during the creation of this book. Their expertise and collaborative spirit enriched my work, and I extend my heartfelt appreciation to each member of the team. Thank you for inspiring me to strive for excellence.
Tamir Al Balkhi is a technology problem solver with 15 years of experience developing innovative and effective solutions for clients across various industries, including healthcare, finance, and retail. From steering small to medium-sized business projects to overseeing large enterprise implementations, Tamir has consistently demonstrated exceptional leadership and technical prowess. As a cloud architect and Chief Technology Officer (CTO), Tamir specializes in designing and delivering best-in-class cloud solutions within the Microsoft Azure ecosystem. His agile-first mindset and commitment to a test-driven delivery approach have been instrumental in his ability to deliver projects on time, within budget, and beyond client expectations.
About the reviewers
Stéphane Eyskens started his career in 1999. Since a bit more than a decade ago, he has been at the forefront of cloud technologies, starting his Azure journey and embracing the emerging K8s platform. As a Microsoft Most Valuable Professional, Stephane contributes a lot by writing blog posts on Microsoft communities, as well as speaking at tech conferences. He has also authored multiple books on Azure and software architecture.
Matt R. Cole has functioned in many different roles over a career of more than 35 years. He was an early pioneer of VoIP. He architected and developed the VoIP system NASA used for all Space Shuttle launches and transmission out to the International Space Station. He worked with Microsoft on Azure Bonsai DRL. Matt led a digital transformation effort for MGM in Las Vegas. He has experience in C, C++, C#, .Net, Python, AI/ML, Swarm Technology, and computational neuroscience.
Matt has authored several books and contributed to several more. His current role is as a senior solutions architect for Dexian, where he works with one of the largest gas and oil companies in the world.
Table of Contents
Preface
Part 1: An Introduction to Your Environment
1
Setting Up Your Development Environment
Creating your Azure subscription
Creating resources in the Azure portal
Configuring your development environment
Installing .NET 6.0
Setting up your local environment for Azure development
Installing Visual Studio Code
Installing Visual Studio Community 2022
Creating your first project
Summary
Part 2: Serverless and Microservices
2
Creating Docker Containers on Azure
Technical requirements
Installing Docker
Exploring Docker and basic Docker commands
Docker architecture
Docker development life cycle
Docker commands
Creating Docker images for your ASP.NET Core application
Containerizing an ASP.NET Core application with the Docker CLI and Dockerfile
Containerizing your ASP.NET Core app with VS Code
Containerizing your ASP.NET Core with Visual Studio
Creating and configuring Azure Container Registry
Deploying web apps to Azure App Service from Azure Container Registry
Configuring CI/CD with ACR
Deploying a Docker image to App service from ACR using managed identities
Summary
3
Building Resilient Applications with Dapr
Technical requirements
Installing Dapr
What is Dapr?
Dapr architecture
Running ASP.NET Core with a Dapr Sidecar
Exploring Dapr’s building blocks
Service-to-service invocation
State management
Publish and subscribe
Enabling Dapr support in Azure Container Apps
Summary
4
Designing Microservices with AKS and Containers in Azure
What is Kubernetes?
How does Kubernetes achieve its goals?
Self-hosted Kubernetes versus Azure Kubernetes Service
Self-hosted Kubernetes
Azure Kubernetes Service
Kubernetes Pods
Kubernetes control plane
Kubernetes Service
Nodes
Persistent Volumes
Deployments
Ingress
Setting up an Azure Kubernetes Service cluster
Troubleshooting Pods and Deployments
Introducing containers
Difference between containers and AKS
When to use Azure Container Instances
Container groups
ACI connector for Kubernetes
Summary
5
Building Serverless Apps with Azure Functions and Container Apps
Overview of serverless computing
Monolithic architecture versus microservice architecture
Resource provisioning and management
Scaling
Cost
Deployment and management
Event-driven architecture
Introducing Azure Functions
Azure Functions use cases
Azure Functions runtime
Azure Functions – in-process versus isolated process
Azure Functions plans
Exploring the Azure ASE
Azure Functions triggers
HTTP trigger
Azure Functions bindings
The host.json file
Delving into Azure Functions security
Authentication and authorization
Managed identities for Azure Functions
Azure Functions access keys
Authorization scopes in Azure Functions
Azure Durable Functions
Elements of Azure Durable Functions
Stateful versus stateless workflows
Application patterns
Setting up an Azure function
Getting started with Azure Container Apps
Azure Container Apps overview
Deploying Docker containers to Azure Container Apps
Deploying a container to Azure Container Apps via the Azure portal
Deploying a container to Azure Container Apps via the Azure CLI
Configuring CI/CD from source control to Azure Container Apps
Summary
Part 3: Data and Storage
6
Exploring Azure Blob Storage
What is Azure Blob Storage?
Types of blobs in Azure Blob Storage
Block blobs
Page blobs
Append blobs
Pricing tiers
Lifecycle management
Transitioning between tiers
Automated data expiry
Rule definitions
Creating a Blob Storage account in Azure
Blob Storage availability
Locally-redundant storage
Zone-redundant storage
Geo-redundant storage
Read-access geo-redundant storage
Choosing the right replication type for your application
Avoiding common mistakes and pitfalls
Understanding the .NET client library
Security in Azure Blob Storage
Public access levels
Shared Access Signature
Azure Active Directory
Role-based access control with Azure AD
Encryption in Azure Blob Storage
Summary
7
Creating an Azure SQL Database
Technical requirements
Introducing Azure SQL Database
Creating an Azure SQL database
Creating an Azure SQL database using the Azure portal
Creating an Azure SQL database using the Azure CLI
Creating an Azure SQL database using the Azure ARM template
Writing and reading data from Azure SQL Database using .NET Core and EF Core
Connecting to Azure SQL Database from ASP.NET Core
Configuring security in Azure SQL Database
Connecting to Azure SQL Server using an identity
Working with system-assigned managed identities
Configuring an Azure SQL firewall
Configuring the Azure SQL Server private endpoint
Summary
8
Creating Documents via .NET for Azure Cosmos DB
Introduction to Azure Cosmos DB
The Document API (SQL API)
The Table API
The MongoDB API
The Gremlin API (Graph API)
Request units in Cosmos DB
Performance and scaling in Azure Cosmos DB
What are throughput, latency, and RUs in Cosmos DB?
Optimizing for throughput in Cosmos DB
Optimizing for latency in Cosmos DB
Optimizing for RUs in Cosmos DB
Best practices for performance and scaling in Cosmos DB
Explaining containers in Azure Cosmos DB
Items in Azure Cosmos DB
Consistency in Azure Cosmos DB
Strong consistency
Bounded staleness
Session consistency
Consistent prefix
Eventual consistency
Understanding partition keys in Azure Cosmos DB
Why are partition keys valuable?
Creating partition keys in .NET
Best practices for using partition keys
Exploring indexes in Azure Cosmos DB
What are indexes?
Why are indexes valuable?
How to create indexes in .NET
Best practices for using indexes
Creating an Azure Cosmos DB database with the Azure CLI
Querying and managing data in Azure Cosmos DB with the .NET SDK
Querying data with the .NET SDK
Using the SQL API
Using LINQ
Managing data with the .NET SDK
Inserting data
Updating data
Deleting data
Managing containers and databases
Using the change feed
Developing with Azure Cosmos DB
Working with the .NET SDK
Cosmos DB cold start problem
Gateway versus direct mode connection
Designing efficient data access patterns
Considerations for performance and cost optimization
Cost optimization
Performance optimization
Monitoring and performance tuning
Summary
Part 4: Messaging Mechanisms and Security
9
Utilizing Azure App Configuration
Technical requirements
Introducing Azure App Configuration
Creating Azure App Configuration instance using the Azure portal
Creating an Azure App Configuration instance using the Azure CLI
Using Azure App Configuration in ASP.NET Core
Dynamic configuration in ASP.NET Core
Exploring feature toggles
Implementing feature toggles from ASP.NET Core
Using features from Azure App Configuration
Summary
10
Processing Data with Azure Event Hubs
Key concepts of Azure Event Hubs
Events
Event producers
Event consumers
Partitions
Event Hubs namespaces
Event ingestion and processing with Azure Event Hubs
Scaling and availability in Azure Event Hubs
Integrating Azure Event Hubs in the Azure ecosystem
How Azure Event Hubs handles event ingestion
Event storage and retention
How Azure Event Hubs handles larger retention periods
Fault tolerance and reliability
Replication, high availability, and disaster recovery capabilities
Setting up an Azure Event Hubs client in .NET
Establishing a connection to an Event Hub
Sending events to an event hub using the Event Hubs client
Processing and handling events in a .NET application
Routing, load balancing, and error handling
Routing events to different partitions
Balancing the load among multiple consumers
Handling failures
Understanding common failure scenarios in event processing
Dead-lettering and handling poison messages
Dead-lettering
Handling poison messages
Monitoring and alerting for failures and errors
Azure Monitor
Azure alerts
Building robust applications with Azure Event Hubs
Configuring access control and permissions for Event Hubs
Using Azure Active Directory for authentication and authorization
Encrypting data in transit and at rest
Best practices to secure Event Hubs in a production environment
Scaling and performance optimization
Techniques to scale event hubs horizontally and vertically
Summary
11
Designing Ready-Made Solutions with Azure Service Bus
Understanding Azure Service Bus
Message queues
Topics and subscriptions
Dead-letter queues
Scheduled delivery
The unique capabilities of Azure Service Bus
Azure Service Bus versus other messaging technologies
Considerations for designing enterprise solutions using Azure Service Bus
Message patterns and communication models
Scalability and throughput requirements
Message durability and reliability
Security and access control considerations
Monitoring, diagnostics, and error handling
Delving into topics and subscriptions
Publishing and subscribing to topics
Filters and rules for message routing
The Competing Consumers pattern with subscriptions
The fan-in and fan-out pattern
Handling dead-letter messages
Scaling and high availability in Azure Service Bus
Scaling out and partitioning with Service Bus
Load balancing and message distribution across namespaces
Availability and disaster recovery considerations
Using geographic redundancy and zone redundancy
Optimizing Service Bus performance
Design considerations for optimal performance
Azure Service Bus best practices
Cost management and pricing tiers
Integrating Azure Service Bus with enterprise architectures
Service Bus and event-driven architectures
Real-world use cases and examples of Azure service bus integration
Message versioning
Creating an Azure Service Bus via the CLI
Summary
12
Enhancing Data Protection with Azure Key Vault
Technical requirements
Introducing Azure Key Vault
Creating an Azure Key Vault service
Creating a key vault from the Azure portal
Creating a key vault using the Azure CLI
Setting up secrets, certificates, and keys
Configuring RBAC permissions for Azure Key Vault
Setting and retrieving a secret from Azure Key Vault
Setting and retrieving a certificate from Azure Key Vault
Setting and retrieving a key from Azure Key Vault
Setting up authentication in Azure Key Vault
Using a system-assigned identity
Using a user-assigned managed identity
Summary
13
Managing Access with Azure Active Directory B2C
Technical requirements
Introducing Azure AD B2C
Different authentication flows
Creating and configuring Azure AD B2C instance
Creating an Azure AD B2C resource
Registering a web application to Azure AD B2C
Creating and configuring user flows
Using Azure AD B2C in ASP.NET Core applications
Different types of tokens
Using Azure AD B2C in single-page applications
Configuring social media login with Azure AD B2C
Summary
Index
Other Books You May Enjoy
Preface
Unlock the power of the cloud and propel your .NET development skills to new heights with this must-have guide to building cloud-native applications and services on Azure. In a world where over 95% of advanced digital workloads are shifting to cloud-native platforms by 2025, now is the time to equip yourself with the knowledge and expertise to stay ahead of the curve. Immerse yourself in a captivating journey as this comprehensive book takes you step-by-step through the exhilarating process of creating and deploying your cloud-native applications on Azure.
With a laser focus on .NET, you’ll dive into the captivating world of containerization with Docker, harness the full potential of Azure Kubernetes Service, and master the art of building serverless apps with Azure Functions. But that’s just the beginning. Prepare to be amazed as this guide unlocks the secrets of Azure’s remarkable container technologies, paving the way for running microservices and containerized apps effortlessly.
Discover the sheer power and flexibility of Dapr, empowering you with APIs for building portable and rock-solid microservices. Resilience becomes your middle name as you explore a plethora of patterns and best practices, leveraging messaging services such as Azure Service Bus and Azure Event Hubs to construct robust applications that never falter. Delve into the world of SQL and NoSQL databases, mastering the art of storing and retrieving data with finesse.
Security takes center stage as you navigate the intricate realm of service implementation, APIs, and authentication with Azure AD B2C. With meticulous attention to detail, this book guides you through proper implementations, ensuring your applications are fortified against potential threats.
But it doesn’t stop there. Unlock the secrets of the 12-factor app methodology as you delve into the realms of configuration and secrets management. Unearth the hidden gems of Azure Key Vault and configuration services, and witness their transformative power in creating harmonious and cohesive applications.
By reaching the final page, you will have conquered a myriad of Azure services, empowering you to construct awe-inspiring, scalable, manageable, and resilient applications and microservices with .NET and Azure. Take advantage of this extraordinary opportunity to embark on a journey that will elevate your skills and propel your career to new heights. Get your copy of A Developer’s Guide to .NET in Azure today and unlock the limitless potential of the cloud-native world!
Who this book is for
Calling all .NET developers and architects ready to embark on an extraordinary journey into the realm of scalable and resilient applications. This book is tailor-made for you, equipping you with the skills and knowledge to develop and deploy awe-inspiring applications using .NET and Azure. With a basic understanding of .NET, you’ll be guided through the enchanting world of Azure, unlocking the full potential of these cutting-edge technologies. Whether you’re a seasoned developer or an aspiring enthusiast, this book is your gateway to mastering the art of building remarkable applications with .NET and Azure.
What this book covers
Chapter 1, Setting Up Your Development Environment, shows you how to set up your development environment for .NET and Azure, ensuring a smooth and efficient workflow.
Chapter 2, Creating Docker Containers on Azure, covers the power of containerization as you dive into creating and deploying Docker containers on the Azure platform.
Chapter 3, Building Resilient Applications with Dapr, explores the world of Dapr and harnesses its APIs to build highly resilient and portable microservices in your applications.
Chapter 4, Designing Microservices with AKS and Containers in Azure, teaches you how to master the art of designing and deploying microservices using Azure Kubernetes Service (AKS) for scalability and efficiency.
Chapter 5, Building Serverless Apps with Azure Functions and Azure Container Apps, shows you how to unleash the potential of serverless computing as you learn to build and deploy serverless applications on Azure.
Chapter 6, Exploring Azure Blob Storage, shows you how to efficiently store and retrieve data using Azure Blob storage for your application’s data storage needs.
Chapter 7, Creating an Azure SQL Database, dives into the world of Azure SQL Database and discovers how to create and manage robust relational databases in the cloud.
Chapter 8, Creating Documents via .NET for Azure Cosmos DB, shows you how to unlock the power of Azure Cosmos DB and its document database capabilities as you build and manage documents using .NET.
Chapter 9, Utilizing Azure App Configuration, explores Azure App Configuration and shows you how to manage and control your application’s configuration with ease.
Chapter 10, Processing Data with Azure Event Hubs, delves into the world of event-driven architectures and shows you how to process and manage data using Azure Event Hubs.
Chapter 11, Designing Ready-Made Solutions with Azure Service Bus, explores the capabilities of Azure Service Bus and shows you how to design robust and scalable enterprise solutions with ease.
Chapter 12, Enhancing Data Protection with Azure Key Vault, shows you how to master the art of securing sensitive data by leveraging Azure Key Vault and implementing robust data protection measures.
Chapter 13, Managing Access with Azure Active Directory B2C, explores the world of identity management and teaches you how to utilize Azure Active Directory B2C for secure access control.
To get the most out of this book
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/A-Developer-s-Guide-to-.NET-in-Azure. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: We will be using the dotnet new mvc command with some extra parameters for supporting authentication using Azure AD B2C.
A block of code is set as follows:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseStaticFiles();
app.MapFallbackToFile(index.html
);
app.Run();
Any command-line input or output is written as follows:
> dotnet new mvc -o Chapter13.MVC --framework net6.0 --auth IndividualB2C --aad-b2c-instance https://pakctchapter13.b2clogin.com --susi-policy-id B2C_1_SignupSignIn --domain pakctchapter13.onmicrosoft.com --SignedOutCallbackPath /signout/B2C_1_SignupSignIn --client-id 43ce7f01-c5f0-4198-b3bc-fed398f319f9 --tenant-id f5aa067e-157b-4b56-b18b-8197479efea7 --callback-path /signin-oidc
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: Once the Azure AD B2C resource is created, we can click on View resource and view the overview of Azure AD B2C.
Tips or important notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you’ve read A Developer's Guide to .NET in Azure, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Download a free PDF copy of this book
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link below
https://packt.link/free-ebook/9781837633012
Submit your proof of purchase
That’s it! We’ll send your free PDF and other benefits to your email directly
Part 1: An Introduction to Your Environment
Kicking off our exploration of Microsoft Azure, this initial chapter aims to help you understand the Azure landscape. We introduce you to the Azure portal, where you can set up every resource that will be discussed in the upcoming chapters. We'll also help you set up your Azure development environment, including selecting and configuring your integrated development environment (IDE) for seamless Azure integration.
This part has the following chapter:
Chapter 1, Setting Up Your Development Environment
1
Setting Up Your Development Environment
Welcome to the first chapter! This chapter will guide you through the steps to set up your development environment and create your first Azure project.
We will start by discussing how to create your Azure subscription, which is the first step in getting started with Azure development. We will provide you with a step-by-step guide on setting up your subscription, including selecting the right subscription type and configuring your account settings.
Next, we will dive into configuring your development environment. This includes setting up your machine with the software, tools, and dependencies required for Azure development. We will guide you through this process, ensuring you have a well-configured environment.
After that, we will set up your Visual Studio for success. Visual Studio is a robust integrated development environment (IDE) that provides the tools to build, test, and deploy your Azure projects. We will show you how to configure Visual Studio for Azure development, including how to set up your project templates and debugging tools.
Finally, we will walk you through creating your first project in Azure. We will provide a hands-on approach, guiding you through creating a new Azure project, setting up your project structure, and deploying your project to the cloud.
In this chapter, we will cover the following main topics:
Creating your Azure subscription
Configuring your development environment
Setting up your Visual Studio for success
Creating your first project
By the end of this chapter, you will have a solid understanding of how to create your Azure subscription, configure your development environment, set up Visual Studio for success, and create your first Azure project. So, let’s get started!
Creating your Azure subscription
You need an Azure subscription to work with examples in this book. In this section, you will learn about how to create an Azure subscription. Let’s get started with the steps:
Open the browser, and navigate to https://azure.microsoft.com/en-in/free/.
Figure 1.1 – Create your free Azure account screenFigure 1.1 – Create your free Azure account screen
Click on the Start free button. On the second screen, you need to create an account. Click on the Create one! link.
Figure 1.2 – Azure account setup – signing in with a live account/signing up for a live accountFigure 1.2 – Azure account setup – signing in with a live account/signing up for a live account
You can use either your existing email address or you can create a new email address. We are using the existing email option.
Figure 1.3 – Creating a live account – email addressFigure 1.3 – Creating a live account – email address
You need to create a password for your account and complete some CAPTCHA verification to create the account. Once it is completed, you will be redirected to an Azure account creation screen.
Figure 1.4 – Azure account profile creationFigure 1.4 – Azure account profile creation
On the screen, you need to provide your personal details, contact information, and your credit card information – for verification purposes. For verification purposes, $2 from your card will be charged and it will be credited to your card within one to two days.
Once the signup is successfully completed, you will be able to see the success page as follows. From this screen, you will be able to access the Azure portal.
Figure 1.5 – Azure account creation – success pageFigure 1.5 – Azure account creation – success page
Click on the Go to Azure portal button to access the Azure portal and you will be able to see a screen like this.
Figure 1.6 – Azure portalFigure 1.6 – Azure portal
The preceding screenshot shows the Azure portal where you can create and manage resources.
In the portal, you can search for resources in the middle search bar, which will help you to search for resources have you created; the available Azure services that you can create; the Marketplace, which you can use to access resources from third-party providers; and documentation on the Azure service you are looking for.
In this example, I am searching for Storage since there is no storage account created. It does not show any existing resources, but the portal shows me services such as Azure Storage Account and Storage browser, and then it shows some Marketplace suggestions and finally, the documentation related to the Storage keyword.
Figure 1.7 – Searching for resources – the Azure portalFigure 1.7 – Searching for resources – the Azure portal
In the portal, after the search bar, you can see a Cloud Shell icon, which helps you execute commands in either PowerShell or Bash shell – you can use this feature to create resources using the command line.
Figure 1.8 – Cloud Shell icon – Azure portalFigure 1.8 – Cloud Shell icon – Azure portal
The Directories + Subscriptions icon will help you switch between different active directories and subscriptions.
Figure 1.9 – Directories + Subscriptions – Azure portalFigure 1.9 – Directories + Subscriptions – Azure portal
Once you click on the button, you will be able to see all directories.
Figure 1.10 – Directories + Subscriptions page – Azure portalFigure 1.10 – Directories + Subscriptions page – Azure portal
In the portal, the notifications icon will show different notifications, such as remaining credit, resource provisioning status, and so on.
Figure 1.11 – Notifications – Azure portalFigure 1.11 – Notifications – Azure portal
Next is the settings icon, which helps you to customize the look and feel of the portal.
Figure 1.12 – Settings – Azure portalFigure 1.12 – Settings – Azure portal
Clicking on the settings icon will take you portal settings page where we have the following options:
By default, it will open the Directories + Subscriptions page.
You can click on the Appearance + startup views menu to configure the look and feel of the portal. In this section, you can also configure the first screen in terms of what you see on it when you log in.
Figure 1.13 – Configure appearance and startup view – Azure portalFigure 1.13 – Configure appearance and startup view – Azure portal
The Language + region option helps you to configure the currency format and date/time value.
Figure 1.14 - Setting up language, date, and currency format – Azure portalFigure 1.14 - Setting up language, date, and currency format – Azure portal
The My information section displays your email address and helps you to subscribe to different emails from Microsoft. You will be able to Export settings, which helps to export your current Azure portal configuration as a JSON file. The Delete all settings and private dashboards option helps you to remove all the settings and dashboards created.
Figure 1.15 – My information – Azure portalFigure 1.15 – My information – Azure portal
Finally, the Signing out + notifications page helps you to configure notifications and sign-out options.
Figure 1.16 – Signing out and notifications configuration – Azure portalFigure 1.16 – Signing out and notifications configuration – Azure portal
Click on the Support + troubleshooting icon to learn about the health status of different Azure services. Also, you will be able to see different links to access billing FAQs, documentation, and the technical community.
Figure 1.17 – The Support and troubleshooting option – Azure portalFigure 1.17 – The Support and troubleshooting option – Azure portal
Click on the Feedback icon to share your experience with the Azure portal.
Figure 1.18 – Send feedback – Azure portalFigure 1.18 – Send feedback – Azure portal
Click on the Show Portal Menu option to see the Azure portal menu.
Figure 1.19 – Azure portalFigure 1.19 – Azure portal
You can customize this menu, which will help you to access different services quickly. The Azure portal comes with a Dashboard view as well. You will be able to create different dashboards and share them with your other team members.
Figure 1.20 – Azure portalFigure 1.20 – Azure portal
Click on the Dashboard button to see your private dashboard – by default, it will show as My Dashboard.
Figure 1.21 – Dashboard view – Azure portalFigure 1.21 – Dashboard view – Azure portal
You can customize the dashboard. You can click on the Edit button, and on the screen, you can remove existing widgets and add different widgets.
Figure 1.22 – Customizing the dashboard – Azure portalFigure 1.22 – Customizing the dashboard – Azure portal
Upon completing the customization, you can preview the changes, and then you will be able to save the changes by clicking on the Save button. You can share the dashboard with other users in the subscription using the Share button.
Figure 1.23 – Share dashboard – Azure portalFigure 1.23 – Share dashboard – Azure portal
In this section, we learned about creating an Azure account and how to customize and configure the Azure portal. You will be able to create and manage different Azure resources from the Azure portal.
Creating resources in the Azure portal
Next, you will learn how to create a resource in the Azure portal:
You need to click on the + Create a resource button.
Figure 1.24 – Azure portal – + Create a resourceFigure 1.24 – Azure portal – + Create a resource
On the next screen, you need to choose the resource you want to create.
Figure 1.25 – Azure portal – Create a resourceFigure 1.25 – Azure portal – Create a resource
For demo purposes, I will create a resource group. It’s a container that contains related resources in an Azure solution. It is a best practice to create resources related to a project or product in the same resource group. You can search for resource group and click on the first result. Then, you will be able to see the details of the service/resource you’re about to create.
Figure 1.26 – Azure portal – new resource groupFigure 1.26 – Azure portal – new resource group
Click on the Create button.
On the Create a resource group screen, provide the name of the resource group – HelloWorld – set Subscription to Free Trial, and set Region to a region near your location.
Figure 1.27 – Azure portal – Create a resource group – Basics screenFigure 1.27 – Azure portal – Create a resource group – Basics screen
Click on the Review + create button to view the details of the resource you’re going to create, and then create the resource upon confirmation by clicking the button again. In the case of a resource group, you will only see the configuration values you created, but in the case of certain resources such as virtual machines or app services, you need to configure mandatory fields – then, you can click on Review + create – in such a scenario, you will be able to see the default values on this screen.
Or you can assign tags to the resource on the Tags tab. Tags are key-value pairs that act as metadata for Azure resources, which helps you to identify resources. Tags are helpful for tracking, organizing, grouping, and analyzing costs for resources. It is a best practice to add tags to your Azure resources.
Figure 1.28 – Azure portal – associating tagsFigure 1.28 – Azure portal – associating tags
Upon clicking the Review + create button again, you will be able to see the details of the resources and the tags:
Figure 1.29 – Azure portal – Create a resource group confirmation screenFigure 1.29 – Azure portal – Create a resource group confirmation screen
This screen will also help you to create an automation script. You can download the Azure Resource Management (ARM) script by clicking on the Download a template for automation link.
Once you click on the Create button, Azure will create the resource group and you will get a notification.
Figure 1.30 – Azure portal – Resource created notificationFigure 1.30 – Azure portal – Resource created notification
This way, you will be able to create resources in the Azure portal. Now you have learned how to create an account and create a free trial subscription in Azure portal. You also learned about how to create resources in Azure using the Azure portal. You will be able to create resources using the Azure CLI and Azure PowerShell as well. Next, you will learn about configuring your development environment.
Configuring your development environment
Setting up your development environment is essential for success because it provides you with the necessary tools and resources to efficiently and effectively develop, test, and deploy your software. A properly configured development environment allows you to streamline your workflow, automate tasks, and catch errors early on in the development process. If you’re new to coding, I’m sure you’re wondering how to set up the right environment for you so that you can get coding quickly and easily. You want to be able to focus on what matters most: creating great code!
There are many different ways to do this, but here is a simple guide that will show you how to set up an IDE for .NET programming on Azure. This guide will give you a solid foundation upon which you can build your knowledge of Python and other programming languages.
If you already have an environment setup, please note we will be working through examples utilizing .NET 6.0 in this book and that needs to be installed on your machine. If you are starting from scratch, follow the instructions below to get started.
Installing .NET 6.0
Follow these steps to install .NET 6.0:
Open your browser and go to this web page: https://dotnet.microsoft.com/en-us/download/dotnet. We will primarily be working in .NET 6.0 so make sure to choose the option related to the system you are using.
Figure 1.31 – .NET Download pageFigure 1.31 – .NET Download page
You need to download the .NET 6.0 SDK. Once the Software Development Kit (SDK) has been downloaded, execute the downloaded executable, which will bring up the following setup screen.
In a Windows operating system, the executable will show a welcome screen as follows (see Figure 1.32) from where you can install the .NET SDK. In Windows, it will prompt for administrator access.
Figure 1.32 – .NET SDK – Windows installationFigure 1.32 – .NET SDK – Windows installation
On Mac machines, it will show a welcome screen like this.
Figure 1.33 – .NET SDK – Mac installationFigure 1.33 – .NET SDK – Mac installation
In Linux distributions, .NET SDK supports two types of installation – manual installation and script installation. With manual installation, we need to download the .NET SDK, execute the files, and configure paths. In script installation, we can download a .NET installation script from here: https://dot.net/v1/dotnet-install.sh. For developers or normal users, scripted installation is recommended. Once we have downloaded the script, we need to make it executable using the chmod command, and then execute the script.
Here are the bash commands to do this:
> wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
> chmod +x ./dotnet-install.sh
> ./dotnet-install.sh
This will install the .NET 6.0 SDK in most of the Linux distributions. You can find more details about the installation here: https://learn.microsoft.com/dotnet/core/install/linux?WT.mc_id=DT-MVP-5002040.
Now that we’ve successfully installed .NET 6.0, we can continue setting up our IDEs.
Setting up your local environment for Azure development
You need to set up and configure the development environment for building your applications in .NET and Azure. In this section, you will configure Visual Studio Code (VS Code) and Visual Studio. Visual Studio Code is an open source editor for building ASP.NET Core and C# applications.
Installing Visual Studio Code
Follow these steps to install Visual Studio Code:
Visit the Microsoft site to download Visual Studio Code: https://visualstudio.microsoft.com/downloads/
Figure 1.34 – Visual Studio/VS Code download pageFigure 1.34 – Visual Studio/VS Code download page
Based on your development machine’s operating system, download the applicable VS Code executable.
Figure 1.35 – VS Code – download pageFigure 1.35 – VS Code – download page
Accept the terms and conditions and continue with the installation:
Figure 1.36 – VS Code EditorFigure 1.36 – VS Code Editor
Unlike on Windows and Mac, installing VS Code on Linux is easy – we just need to run the following command: sudo snap install --classic code. This will install VS Code on Linux. For more information on the VS Code installation, check out this page: https://code.visualstudio.com/docs/setup/linux.
Click on Extensions or press the Ctrl + Shift + X shortcut keys on Windows or Cmd + Shift + X on Mac and install the following extensions:
Azure Tools
Azure CLI Tools
Azure Pipelines
Azure Kubernetes Service
Azure Storage Explorer
C# Extension
Installing Visual Studio Community 2022
Follow these