Azure App Service, Azure Cloud, Azure Cosmos DB, Cloud Computing

How to use NoSQL Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications: Part 6

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications

Azure DocumentDB or Azure Cosmos DB is database for very low latency and immensely saleable applications, which have global audience and it provides native NOSQL support. Azure cosmos DB support storing and retrieving JSON object at scale.

During development you do not need to create a new instance of documentDB, visual studio provide you the emulator to use during development phase. To explore the possibilities, In our case, we will create Azure Cosmos DB / documentDB on azure and use it in our application that we are building in this series.

In Azure first we need to create an account for Azure Cosmos DB and then we can create collections and databases in it. Let us do just that.

Go to Azure Portal and Click on Add and search for documentDB | select Azure Cosmos DB and click on create.

Figure 1 Create Azure Cosmos DB

Now fill the form, select the API, Azure support multiple APIs like SQL API, MongoDB API, Graph API, Table API and Cassandra API, and choose the appropriate API, we are going for SQL API. This will create a new Azure Cosmos DB account for you.

For more info on APIs

Figure 2 Create Azure Cosmos DB

It may take some time to create it. Once created go to the resource | select your documentdb account | Quick start. Right now, we do not have any collection and we do not have any database. Firstly we will create new collection, and then create database in that collection, but we have a short cut to do just that, click on Create Items collection button. It will create the basic collection for you which will cost you around 0.033$ / hour and will give you 400 reads/sec. Read/sec defined as if the file is 1 kb size and 1 kb file read is represented as 1 RU  then 400 request could be read per second 400 RU/S and under 400 RU/S load, our current documentDB will work just fine. If the requests are, more the throttling will happen and latency will increase, in case of extreme throttling request timeout could happen. Writing operation will cost you more than reading, Writing the file of 1 Kb size will cost you 5 RUs as it is more expensive then read. You can check following link for more info

Figure 3 Create Items collection in Azure Cosmos DB

Click on Create “Items” collection” and then click on  download  button to get the code for TODOList sample Project, we will use this project as sample and will modify our existing project to communicate with the Azure Cosmos DB.

Now go to Collections | Browse you will see that it created new collection Items and database in it called ToDoList , all we have to do now is to integrate todo project we have downloaded, to our app that we are building in this series.

Figure 4 Azure Cosmos DB collections and database

Open the downloaded sample source code in the visual studio and run for few times and add some records. This will create some record in the database that we will see later and we will also clear some misconceptions about documentDB that many developers may have.

Figure 5 Run TodoList sample project

Open DocumentDBRepository, this is our main file, which is communicating with Azure Cosmos DB, and notice it is using , endpoint, authKey, database and collection app settings. We will copy the DocumentDBRepository.cs file and include appSettings to our exisitng application.

Figure 6 DocumentDBRepository

Make sure to install Microsoft.Azure.DocumentDB package through nugget.

Figure 7 Install Microsoft.Azure.DocumentDB

Make sure copy all the files highlighted and change _layout.cshtml file to include our Item controller also highlighted.

Figure 8 migrated the code

Also, make sure you copy below to Global.asax.cs | build  | check locally that there is no error while building or running, and publish the changes to App Service, we have already covered how to publish the source code to app service in previous posts.

DocumentDBRepository<todo.Models.Item>.Initialize();

Figure 9 Insert DocumentDBRepository initialize line

Now once your project run successfully, insert records few times by creating some tasks. Keep in mind that we can use To-do Items example to insert any JSON serializable object in the same collection even if the object do not relate with each other, DocumentDB is not limited to structure like table, you can insert any object of any type given that it is serializable to JSON or can be represented in JSON format.

Figure 10 insert few To-do items in documentDb

Sample code is also given below:

We can also verify the data is inserted through Azure Portal, Go to your Azure Cosmos DB | Collections | Document Explorer | click any item | you will see the data in document tab in JSON format.

{


“id”: “d2dc5626-e279-4390-b079-f6ba1a4af982”,


“name”: “test3”,


“description”: “test3”,


“isComplete”: false

}

Check for more information

At this point you are successfully integrated your existing project to use the Azure Cosmos DB.

Coming up next How to use Visual Studio Team Service to do continuous Integration and continuous delivery

 

Azure App Service, Azure Cloud, Azure SQL Database

How to use Azure SQL Database in Dot.net Applications: Part 5

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

5. How to use Azure SQL Database in Dot.net Applications

At this point, if you register with the app, which we have built earlier in this series, you will get an error, as we have not created or configured the Azure Database. It is time to get our hands on Azure SQL database.

Figure 1 Error while registering for new user.

Go to Azure Portal and Click on Add and search for SQL Database | select SQL Database and click on create.

Figure 2 Create SQL Database

When you create a SQL Database it will ask you to create Server as well, but you should not think this as a physical installation of the SQL server, in fact it is not even a virtual database server on azure but a logical container, this is just a container which will have databases you create. This databases you create in same container/Database server, do not mean that they will be in the same database server physically, Microsoft manages the infrastructure and although this logical container/database server will behave the same as if, you are using SQL management tools to manage it on premises installed MS SQL Server.

Figure 3 Create SQL Database and SQL Database Server container

Next in our list is elastic Pool, it is to manage the performance level and pricing etc. on a group of databases rather than selecting the performance level etc. in pricing tier for single database, which we do in case of single database creation mode. Be noted the pricing plan we are choosing, is per database basis and is not per container/database server as we are not going for elastic pool. If you have multiple databases, then choosing elastic pool will save you a lot of money.

For more information

Click on pricing tier and select the appropriate tier, we will choose the basic one as this is developer guide but in case of production workload, please go for at least standard pricing tier.

Figure 4 SQL Database pricing tier

As you can see, we have DTU as compared to previous metric, where we had CPU and RAM etc. DTU is just representation of the relative resources assigned to database, which include CPU, memory and read-write rates.

For more information on DTU

Select Basic | apply | create, to create database. It may take some time to create, do not worry if it takes time to complete. Once the database is created, Click on database and you will see screen like below:

Figure 5 SQL Database dashboard

By default, the SQL Database is accessible inside the Azure data center by other azure services and is not accessible outside, luckily, there is an option to add your current IP address and that way it is could  be accessible to you outside azure as well. Note that your current IP address may change over time, and it not your true static IP address, may be latter you connect to Azure your public IP change or can be assigned to other users, so it is best to remove it when you are not accessing database outside azure. You have an option of connecting this database in virtual network as well, in case you have some VM(s) or other services to communicate with each other.

Figure 6 Firewall settings SQL Server

Click Add client IP and save.

Now it is time to connect to the database using SQL Management Studio, if you do not have it, download it and install or you can even use visual Studio to connect to the database server. We are going to use SQL Management studio, open SQL Management Studio and put your credentials and connect, you will notice that the ICON of the server is changed that is because it is connecting to Azure SQL database server, also notice that the database is listed under database heading, which we had created earlier.

Figure 7 Connecting to Azure SQL Server using SQL Management Studio

Please note that the User we have used is admin user and it have access to all the databases that we have in our container/Database server, in order to limit the access you need to create new user. If it asks for you to connect with your Azure Subscription account while connecting to database server then do it, because by default, the Azure SQL Server will not be accessible to any one and by logging with your Subscription Account will add your IP address to white list for you automatically.

Let us create a new user for our application, after login go to Object Explorer | Security | Login | New Login, enter your credentials and Press F5 to execute the query.

CREATE
LOGIN myWebAppUser

    WITH
PASSWORD
=
YRY:)Q5t[{VB

GO

Figure 8 Create New User using SQL Management Studio

After that we need to create the user on database level and map this to Login we created in previous step and give the database role, for us we gave “db_owner” role, you can coordinate with your DBA to get the appropriate roles for your application user.

CREATE
USER myWebAppUser

    FOR
LOGIN myWebAppUser

    WITH
DEFAULT_SCHEMA
= dbo

GO

— Add user to the database owner role

EXEC
sp_addrolemember
N’db_owner’,
N’myWebAppUser’

GO

Figure 9 Mapping login user to Database user and giving database owner role

Now let us create our connection string and add it to our portal, you can also add it to release web.config in visual studio but to make it secure, it is best practice to not mention the staging or production connection string in source code.

Figure 10 Web.config

Go to Azure Portal| database | connection strings | Ado.net copy the connection string and update it with your username and password in any text editor.

Figure 11 Get Azure SQL Database connection string

<add
name=DefaultConnection
connectionString=Server=tcp:scientistzdbserver.database.windows.net,1433;Initial Catalog=scientistzDB;Persist Security Info=False;User ID=myWebAppUser;Password=YRY:)Q5t[{VB;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;/>

Now we will configure our App Service with the above connection string, for this we need to know the connection string name that is being used in our application. Go to Web.config and Connection string section, as we can see it is “DefaultConnection”

Figure 12 Get name of the connection string

Go to your App Service | Application Settings | Connection strings | add connection string you have created in previous steps | check Slot setting check box and click save.

Figure 13 Add Connection string to App Service

Now try to register again on your main application.

Figure 14 register new user in application

It will take some time to complete this first request, when the website automatically refresh you will see now you are successfully registered in the application.

Figure 15 Successfully Registered on App Service

If you go back to SQL Management Studio and refresh the tables you will see that our application have created new tables, when we registered for first time, that is why it took time for the very first time to complete the request. All the later requests for registrations will happen immediately. Right click on “dbo.AspnetUsers” and select “Select Top 1000 rows” and you will see the record created by entity framework and you can see the “_MigrationHistory”, which mean code first entity framework model is used.

Figure 16 New Tables are created after first registration request

With this congratulation, you know now, how to use Azure SQL database in our dot.net Applications

You can also visit official page of Azure SQL Database

Coming up next How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications

Azure App Service, Azure Cloud

Diagnostic logs, live stream, process explorer and KUDU: Part 4

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

  1. Diagnostic logs, live stream, process explorer and KUDU

Logs are essential part of every developer’s life; it gives us the detailed information about what is going on in our system in specific date and time. Azure App Service enable us to log on many levels i.e. IIS level, Application level etc. to satisfy our needs. Let us look into few important ones to get started.

Go to Azure Portal and then App Service | Monitoring | Diagnostic logs, by default Diagnostic logs are disabled as you can see in the below picture.

Figure 1 Diagnostics logs disabled

To view application logs you need to turn on Application logging, we have two options here one is Filesystem and other is Blob, filesystem logging is used to stream logs live and have disadvantage that it will turn off after 12 hours, but in blob case, it will keep on going for ever unless you reach the Storage account limit. This is because the filesystem logs may fill up the App Service Plan storage but in blob logging, it can keep on going as we usually have a larger blob storage in azure.

When we enable the Filesystem logging, options are self-explanatory. If you want to log everything, you should choose verbose option.

Figure 2 Enable Application logging (filesystem) verbose

Web server logging will give us IIS Logs. Detailed error messages is to override settings for custom error and failed request tracing enables IIS failed request feature, this feature could be helpful in tracing the issues which may not appear in application logs as the request may not be reaching to your applications and in this case failed request tracing is the way to go.

Figure 3 Diagnostic Logging types explained

Now you would be wondering we enabled all these logs where could we find these logs, you can connect to server using ftp and get the logs or use KUDU to get these logs, which I will show later in this post. Let us move to live stream, which is a handy way of viewing logs on Azure portal.

Figure 4 ftp logs download

Go to Diagnostics | Live Stream, you would see now the information related to the application in Application logs tab and information about IIS is in web server logs if you have enabled both first in diagnostics.

Figure 5 Application Logs in Live Stream

Remember that even though name suggest that it is Live Stream but it may take few minutes for logs to show up, so do not worry if you do not get logs right away.

If you are interested in, which processes are running in your App Service, then you look them in Monitory | Process Explorer. This will provide you basic information about CPU and memory, but you can get more information about running processes in the tool called KUDU.

I have mentioned many times the tool KUDU, this is time to look what is KUDU and how to use it, Go to Azure Portal and then App Service | Development Tools | Advanced Tools | GO, this will open [your site].scm.azurewebsites.net and as you can see; it have many tabs including Process Explorer

Figure 6 KUDU Advanced Tools in App Service Plan

Now as you can see, this tool provides you robust information and you can even drill down and check the properties or start profiling.

Figure 7 Process Explorer in KUDU

Figure 8 KUDU process explorer properties

Kudu have many useful tools, one is Diagnostic dump, and this option will get all the logs and give a single zip file for you. You can see it have log stream and web jobs, web hooks and even deployment script for the App Service with current configuration in case you need to replicate it on another data center.

Figure 9 Kudu Diagnostic dump and log stream

There is another way, we could get the logs files using KUDU, let us do that now. Choose Debug console and then click on CMD. You can use fully functional CMD here; try some commands. Now click on LogFiles

Figure 10 Debug console CMD

You will find all the logs here and can even download them to your system as well. If you want to explore files which you deployed click on … and go to site | wwwroot and all the files will be listed there and if you change any file then in case; your application is running on multiple servers then this change will be replicated automatically and you don’t need to worry about changing it in every server.

Figure 11 Log files in KUDU

Azure also have Application Insights, which is free to start but will charge you if telemetric data is exceeding the free limit, it give you tremendous amount of information about performance and health of your resources,

I have put together a post regarding basic installation on WordPress but it could be used as starting point

Figure 12 Application Insights Overview

For more information:

https://docs.microsoft.com/en-us/azure/application-insights/app-insights-overview

Application Insights even offer you SDK to carve up your own solutions. Remember that in order to enable Application Insight to get the data about your application you may need to install Application Insight nugget package in your application.

Coming up next How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications

 

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Remote debugging App Service using visual Studio, monitoring and configuring alerts: Part 3

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

  1. Remote debugging App Service using visual Studio, monitoring and configuring alerts

We have successfully configured the deployment slot in previous post, now we are going for remote debugging. In Azure remote debugging using visual Studio is not enabled by default, you have to enable debugging for specific VS version to debug. Although if you have permissions you can do it by Visual Studio if you do not have enough permissions, please ask your Azure Subscription owner. In our case we are the owner of Azure Subscription so we will proceed for debugging with out requiring any permissions,

If you have not already opened your visual studio, then open it and load the project you had deployed earlier. Now go to Cloud Explorer | your subscription | Select your app | Actions | Click on Attach debugger.

Figure 1 Remote Debugging

Debugger will be attached, it may take some time depending upon your internet connection speed and your location distance to Azure Data center, If you are getting error like below, that means you do not have permissions to debug or you have not enabled Debugging for your App Service, remember by default debugging is not enabled. In my case, it was referring to firewall settings and we found out that there were some ports closed which needed to be opened to communicate with Azure.

Figure 2 Error While connecting to Remote Debugging Session

Go to Azure Portal and then App Service | Settings | Application Settings | Debugging | enable Remote debugging and also choose visual studio version and click save. Now by this step your debugger should be attached successfully.

Figure 3 Enabling Remote Debugging

If you still not able to resolve the problem please consult my recent post which discuss the steps to fix common debugging issues.

Also check Microsoft page

Once you are in debugging mode, you can use all the tools that you use while debugging locally.

App Service Monitoring

Let us move on to monitoring our App Service.

Azure provide you multiple ways to monitor your App Service, Let us explore them, go to Azure Portal and then App Service | Overview, in this view you can see the basic information about http errors, data in, data out, number of requests and Average response time. All though this view will satisfy most users, but you can even drill down and generate custom views for you as well, just click on any of the chart and you will see a new view, in which you can tailor the chart according to your metrics.

Figure 4 Monitoring performance

For demo, We have added CPU Time into the mix, and we can see that display show both Average Response Time and CPU Time as well.

Figure 5 Create Custom chart

You can click on Pin to dashboard to see it on your main dashboard as well.

Figure 6 Pin to dashboard

Alerts

This bring us to our next topic alerts, alerts can be very useful especially when you have a lot of resources and do not have time to manually check the metrics to see what is going on. We can create alert right on a particular metric by clicking on

Or App Service | Monitoring | Alerts

Let us create an alert on CPU Percentage on our App service Plan ( it will include all the apps hosting on same App Service Plan) and choose CPU Percentage and set condition to “greater than” and threshold to 80. You will notice that the chart shows you current CPU percentage in dotted line and the threshold in straight line, do not forget to check email owners check box if you are the owner and want to get the alert email otherwise there is a textbox to add addition emails or call a webhook. Webhook is a restful endpoint, which is publically accessible to Azure and will be called when metric pass the condition we set. Mostly developer use webhook to initiate a workflow, which could for example increase number of running instances through PowerShell script or initiate a business workflow. To learn more about webhook see https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts

Figure 7 Create alert on CPU percentage for App Service Plan

As you, can see that I have created two alerts, one for CPU percentage and another for Memory percentage. Now when ever condition you set will meet you will get an email or a webhook will be called. Alerts truly simplify our monitoring task specially if we have a lot of resources to worry about.

Figure 8 Create Alert on CPU and Memory percentage

Congratulations, you have successfully debugged and monitored your application and configured alerts.

Coming up next Diagnostic logs, live stream, process explorer and KUDU

 

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK: Part 2

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK

At this point, you have successfully created the App Service Plan, App service and published the changes to the Azure using Visual Studio and Azure SDK. Let us move to exciting part of remote debugging and monitoring, fire up your visual studio if you have not opened it before and open the project we created in recently.

Figure 1 App Service Deployment Slot

Let us talk about Deployment Slot, this is feature provided by App service, this basically enable you to deploy your code to different containers i.e. QA, Staging or Production, in this way you will make sure that your code is fully tested and ready to move to production. This approach support setting up different App Settings and connection strings for the Databases for each slot, which will enable us to test and deploy our changing with ease.

I know you are excited about this feature lets, let us open web.config and add a new App Setting

<add
key=WelcomeMsg
value=Welcome to Azure Development!/>

Figure 2 Add new App settings in web.config

Now show this setting in our index page, Views | Home | Index.cshtml and edit it as shown below:

@using System.Web.Configuration;

@{

ViewBag.Title = “Home Page”;

}

<div
class=”jumbotron”>


<h1>ASP.NET</h1>


<p
class=”lead”>@WebConfigurationManager.AppSettings[“WelcomeMsg”]</p>


<p><a
href=”https://asp.net&#8221;
class=”btn btn-primary btn-lg”>Learn more &raquo;</a></p>

</div>

Figure 3 Edit Index file

Now after this change just press F5 to lunch and see the change.

Figure 4 App setting message is showing

Now publish your solution to the Azure App service as we did in our previous post. You can see that new changes publish.

Figure 5 Publishing Changes to Azure App Service

We will override the changes in our App Service Settings; go to Azure Portal and then App Service | Settings | Application Settings, here we will add the key and value to override the default one, please note that we can also use this interface to add new keys as well, this interface is not limited to just overriding key values.

Figure 6 Override Application Settings in Azure Portal

Now refresh to see that message is changed as expected.

Figure 7 Override setting display

Now let us create slots for staging slot. Go to Azure Portal and then App Service, Deployment | Deployment Slots | Click Add Slot and name it as staging, in configuration Source choose the main app and click ok. It could take few minutes depending upon application size.

Figure 8 Add new Staging Deployment Slot

Once deployment slot is added successfully, click on it to see the settings.

Figure 9 Deployment Slot is added successfully.

Change the “WelcomeMsg” to “Welcome message from staging” and tick “slot setting” check box, as when we swap this deployment slot with production this setting will not move and will stay with this slot. This way we will be able to retain the settings that are slot specific.

Figure 10 Change App settings on Staging Deployment Slot

Now question arise how we are going to deploy our source code to staging slot, the answer is very simple Publish Profile, click on Over view and then click on Get Publish Profile and save it to local system.

Figure 11 Get Publish Profile Setting

Go back to visual studio | Publish and click on Create new profile, select Existing check box, click on import profile, click ok, select the staging profile that we got in previous step and click ok.

Figure 12 Import Profile

Figure 13 Import profile and publish

For testing purposes open Index.cshtml file and update it as below

<p
class=”lead”>We have update the project</p>

Figure 14 Update for staging

Publish the changes to staging slot by just clicking on publish; we can see that our recent changes have been published successfully.

Figure 15 Publish changes to staging slot

All these steps lead us to the exciting part of Deployment Slot Swap, Go to Azure Portal and then App Service, click on swap and click ok.

Figure 16 Slot Swap

Figure 17 Choose Swap Slot

Swapping operation will take some time to complete, in side-by-side comparison you can see that staging code is swapped to production and production code is swapped to staging. Remember that user will be experience any downtime in this operation will continue to use the application as they were before swap.

Figure 18 Production and Staging slot swapping

With this congratulation, you have successfully created new staging slot, deployed your code to staging slot, used sticky slot settings, and swapped production with staging.

Coming up next Remote debugging App Service using visual Studio, monitoring and configuring alerts