Introduction to App Settings in Azure Web Apps

In the recent post we discussed about Defining and Using Connection Strings in web apps for securing login credentials of database or any crucial thing. Today we will talk about App Settings that is similar to Connection Strings but is used for different purposes. For example, connection strings is used for connecting your Web App to Database or Server or any similar thing, but App Settings is used to define the mechanism of the Web Apps. You might want to change the behavior of your Web App (or something same like that) then you can probably go with App Settings in Azure.

Today I will show you how to change color of Label in ASP.NET basic site. This gives you a good demonstration and gives you THE best idea of flexibility of Azure in Web Apps.

Note: I do have a basic ASP.NET site for this demo. You might need to start from new project.

Defining App Settings in Azure Web App

Step 1: In your Azure Portal go to your website’s dashboard then click on Configure Tab.

Go to Configure Tab
Figure 1: Go to Configure Tab

Step 2: Scroll down to App Settings.

Step 3: In the list, type a name for the setting in the text box with placeholder text KEY and type a value for the setting in the text box with the placeholder text VALUE.

Defining App Settings
Figure 2: Defining App Settings

Step 4:
Click SAVE on the command bar to apply all the changes.

Click Save
Figure 3: Click Save

Using App Settings from .NET

Now that we have created and saved app settings for the color of label. Now we will use it in our ASP.NET site which I created earlier. I assume you have already created an Azure .NET Web App or ASP.NET site.

Step 1: Open your project and your page where you want the connection string to be retrieved (I have it on default.aspx).

Step 2: Enter the following code snippet in default.aspx.cs page.

  1. using System;   
  2. using System.Configuration; // You need this declared  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8.   
  9. namespace ravitestwebsite  
  10. {  
  11.     public partial class _default : System.Web.UI.Page  
  12.     {  
  13.         protected void Page_Load(object sender, EventArgs e)  
  14.         {  
  15.             string key = "labelColor";  
  16.             string colorValue = ConfigurationManager.AppSettings[key];  
  17.             label.Text = "I got my color from Azure.";  
  18.             label.ForeColor = System.Drawing.Color.FromName(colorValue);  
  19.         }  
  20.     }  
  21. }  
In default.aspx page add a label in the site as in the following.
  1. <asp:Label runat="server" id="label"></asp:Label>  
Step 3: Now publish your site to Azure and run it.

Deployed Site
Figure 4: Deployed Site

Let’s change the color and deploy it and see the changes.

Value Changed
Figure 5: Value changed

Color changed
Figure 6: Color changed

See guys how easy it is to use app settings. This is a basic example. Just think in what ways this can be used. The power of Azure in unbelievable. If you got any query or any idea regarding how to use this comment down below.

Cheers!

 

Up Next
    Ebook Download
    View all
    Learn
    View all