Creating an ASP.NET Web App by Using Azure Web Apps
Web Apps is a low friction Platform-as-a-Service (PaaS) offering to host your web applications in the Azure platform. In this article I will show how to create, deploy and configure azure web app.
The first step is we need to create Web App instance by using the Azure portal, and to do that we need to follow these steps:
- Go to Azure portal. In the email address box, type the email address of your Microsoft account. In the password box, type the password for your Microsoft account. Then click Sign In.
- In the navigation panel on the left side of the screen Click on Resource Group then click on +Add option and then enter the value [Resource Group Name] and select the subscription and location into the dialog box.
- In the navigation panel on the left side of the screen, click App Service
- In the New blade that appears Click on + Add
- Select Web App and then Click on Create Button.
- Fill the app name and select the created resource group then click on app service plan to create new plan.
- In New Service plan dialog fill the name and click on pricing tier to select one
- Select F1 then click Apply.
- Wait until it finishes.
- Now we need to create a new Web App through Visual Studio 2017. Open visual studio from file cand lick new project. From cloud section select ASP.NET Web Application (.NET Framework), change the name and then click OK
- Select MVC and then click OK button.
- Modify the web as you need, after finishing right click on project solution and select publish
- In publish dialog select “select existing” option, then click on publish button, the select the subscription, recourse group and target web app instance.
- Select publish to start publishing the web to azure.
- After completing the publishing you can open the web from recourse group, open web app, from app service dashboard you can find the URL.
Configuring an Azure Web App
Now we need to configure the web app by adding a new app setting in web config and reflect that in Azure.
- From Visual Studio, Open the web.config, in appSettings section, add new app settings tag
- Create new class and replace the code with the below code,
- public static class HRHelper {
- public static string CompanyName {
- get {
- return ConfigurationManager.AppSettings["CompanyName"];
- }
- }
- }
- Open _Layout.cshtml from shared folder and replace the footer section with the following code,
- <footer>
- <p>© @DateTime.Now.Year - @HRWebApp.Helper.HRHelper.CompanyName</p>
- </footer>
- Now publish the project to Azure by clicking in publish context menu, in publish dialog click on Edit App Service Settings and then add the app setting key and value. Then click publish.
- To modify the value from Azure, open your app service, under settings click in application settings, now you can find the app, and see and change the key and value.