Build and Deploy Web Application as Azure App Service Web App

Deploying your app to App Service is a matter of deploying your code, binaries, content files, and their respective directory structure, to the /site/wwwroot directory in Azure (or the /site/wwwroot/App_Data/Jobs/ directory for WebJobs).

  1. Create a Web App in Azure Portal
    1. Login to Azure Portal, https://portal.azure.com/
    2. Azure Portal => More Services => Web App => + Add
    3. Select Web Apps => Create
    4. Name = “DssDemoWebApp”, Subscription = “Free Trail” Resource Group=”DemoRG”, App Service plan/Location=Create New Plan (Name=Standard_Plan, Location=Central US, Pricing tier=S1 Standard.
    5. Application Insights=Off
    6. Create
  2. Visual Studio  => Create a new ASP.NET MVC Web Application in Azure Web Service
    1. File => New => Project
    2. Visual C# =>NET Web Application, Project Name=”DemoWebApp” => OK
    3. Select Template = MVC, Change Authentication = No Authentication => OK
    1. Deploy / Publish the project from VS.NET.
      1. In Solution Explorer, right-click the project, and choose Publish.
  3. The wizard opens to a publish profile that has settings for deploying the web project to the new web app. If you wanted to deploy to a different web app, you could click the Profile tab to create a different profile.
    1. Choose default options and finally click on Publish.

    The Output and Azure App Service Activity windows show what deployment actions were taken and report successful completion of the deployment.

  4. Getting Publish Profile from Azure Portal and publishing from Visual Studio
    1. Click App Services, and then click the name of your web app.
    2. In the tool bar click on Get Publish Profile
    3. Save the Profile locally on your disk.
    4. Go to VS.NET, Right Click on Project => Publish
    5. Select Profile Tab => Click Import => Provide the downloaded profile name => OK
    6. Click Publish.Note: Profile will be saved for further use in <Project>/Properties/PublishProfiles/*.pubxml

To Gets an Azure Web App publishing profile using PowerShell:

Get-AzureRmWebAppPublishingProfile -ResourceGroupName "DemoRG" -Name "DemoWebApp" -Format "WebDeploy" -OutputFile "D:\outputfile.publishsettings"

Publishing using FTP tools like FileZilla

  1. Azure Portal => Click App Services, and then click the name of your web app.
  2. Go to Settings => select Deployment Credentials
  3. Provide FTP/deployment username and password
  4. Save
  5. Look at Essentials Section of Selected App Service and copy FTPS hostname and username
  6. Open Windows Explorer and use the above hostname and credentials to connect and upload files.

Note: Although it’s easy to copy your web app’s files to Azure using FTP utilities, they don’t automatically take care of or coordinate related deployment tasks such as deploying a database or changing connection strings. Also, many FTP tools don’t compare source and destination files in order to skip copying files that haven’t changed. For large Apps, always copying all files can result in long deployment times even for minor updates since all files are always copied.


SandeepSoni.jpg

Mr. Sandeep Soni, CEO & Founder of Deccansoft Software Services.He has over 21years of Experience in Teaching and Development using Microsoft Technologies. Since 1997, of the total 100000+ students Deccansoft has trained, he has personally trained over 60,000+ students and we are proud of him because almost every student he had trained is very happy with the quality and many are well placed in various I.T Firms.

Using Azure SQL Database with EF Code First

  • Open the existing ASP.NET MVC Web Application or Create a New Application.
  • Go to Tools => NuGet Package Manager => Manage Nuget Packages for Solution
  • Add reference to EntityFramework
  • To the ASP.NET MVC Web Application add the following in Employee.cs under Models folder.
public class Employee
    {
        [Key]
        public int Id { get; set; }
        public string EmpName { get; set; }
        public decimal Salary { get; set; }
    }
    public class DemoOrganization : DbContext
    {
        public DbSet<Employee> Employees { get; set; }
    }
  • In Web.Config add the following
<connectionStrings>
    <add name="DemoOrganization" connectionString="Data Source=.\sqlexpress;Integrated Security=True;database=DemoOrganization" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  • Right Click on Controller Folder => Add => Controller…=> Select “MVC 5 Controller with Views, using Entity Framework” => Add
  • Select Model = Employee, DataContext Class = “DemoOrganziation” => Add

Note: This generates Controller along with Views for Add/Edit/Delete operations.

  • Go to Tools => NuGet Package Manager => Package Manager Console => At prompt Execute Commands, Enable-Migrations
  • Open the Migrations\Configuration.cs file and add the following to Seed method.
context.Employees.AddOrUpdate(
  p => p.Id,
  new Employee  { EmpName = "E1", Salary=1000 },
  new Employee { EmpName = "E2" ,Salary=2000},
  new Employee { EmpName = "E3" ,Salary = 3000}
);
  • In the Package Manager Console enter the command:

                 Add-Migration “Initialize”

                  Update-Database

  • Run the application locally.

Publish the App to Azure:

  • Azure Portal => Create Sql Server and Database
  • Azure Portal => Create a New WebApp
  • In Visual Studio => right-click the project in Solution Explorer and select Publish from the context menu
  • Under Profile Tab => Click on Microsoft Azure App Service
  • Click on New Button, Go to Services Tab => Click on SQL Database + => Create a New Database => Provide a Database Name, Administrator Username, and Password => OK

OR

  • Under Settings Tab => Provide Database Details and Check “User this connection string at runtime (update destination web.config)” and Also check => Execute Code First Migrations (runs at application start)
  • Publish the Web App and Note the progress in Azure App Service Activity Window
  • Test the application by visiting http://<DemoApp>.azurewebsites.net/Employees.

Part 2:

  • Add “Age” column to the Employee class
  • Delete EmployeesController and corresponding views.
  • Recreate EmployeesController as in step 6 and 7.
  • In the Package Manager Console enter the command:

Add-Migration “AddAgeColumn”

Update-Database

  • Publish the Application and ensure that in Settings, ensure that “Code First Migration…” A checkbox is checked.
  • Test the application by visiting http://<DemoApp>.azurewebsites.net/Employees.

SandeepSoni.jpg

Mr. Sandeep Soni, CEO & Founder of Deccansoft Software Services.He has over 21years of Experience in Teaching and Development using Microsoft Technologies. Since 1997, of the total 100000+ students Deccansoft has trained, he has personally trained over 60,000+ students and we are proud of him because almost every student he had trained is very happy with the quality and many are well placed in various I.T Firms.

Azure Hosting Models

Azure Hosting Models: Azure includes many services in its cloud computing platform. Let’s talk about a few of them.

Azure provides different hosting models for running applications. Each one provides a different set of services, so which one you choose depends on exactly what you’re trying to do.

  1. Virtual Machines
  2. App Services
  3. Cloud Services

Virtual Machines

  • With support for Linux, Windows Server, SQL Server, Oracle, IBM, and SAP, Azure Virtual Machines gives you the flexibility of virtualization for a wide range of computing solutions—development and testing, running applications, and extending your datacenter.
  • Azure Virtual Machine enables you to create a server in the cloud that you can control and manage, customize the VHD settings of the VM, create multiple VMs and load balance traffic between them.
  • Combine the performance of a world-class supercomputer with the scalability of the cloud. Scale from one to thousands of virtual machine instances. Plus, with the growing number of regional Azure datacenters, easily scale globally so you are closer to where your customers are.

Cloud Services:

  • It is Microsoft’s Platform as a Service (PaaS) environment used to create scalable, reliable and low admin applications and services. The applications are built with roles. A role represents a single component built with managed code, which runs in the Azure environment in a virtual machine (instance).
  • Support not only web-based deployments but also multi-tier architectures where you might have a combination of front ends, middle tiers, as well as virtual machines running as part of your solution.
  • Supports automated application management, so it is really easy to deploy, scale out, isolate, and recover from any type of hardware failure.

App Services

  • Azure App Service is the only cloud service that integrates everything you need to quickly and easily build web and mobile apps for any platform and any device.
  • App Service allows you to host the following app types:
  1. Web Apps: Create and deploy mission-critical web apps that scale with your business. Supports .NET, Java, PHP, Node.js, and Python.
  2. Mobile Apps: With the Mobile Apps feature of Azure App Service, it’s easy to rapidly build engaging cross-platform and native apps for iOS, Android, Windows, or Mac; store app data in the cloud or on-premises; authenticate users; send push notifications, or add your custom backend logic in C# or Node.js
  3. API Apps: API Apps lets you take your new and existing APIs and automatically generate SDKs for a variety of languages, including C#, Java, JavaScript, and more—empowering your business to easily use your APIs for web, mobile, and desktop applications.
  4. Logic Apps: The Logic Apps feature of Azure App Service helps keep your marketing and analytics SaaS apps in sync. Extend business processes in minutes. Boost sales productivity by reducing data entry.

Note: Virtual Machines, App Services, and Cloud Services can be used separately or combine more than one to create an application.

SandeepSoni.jpg

Mr. Sandeep Soni, CEO & Founder of Deccansoft Software Services.He has over 21years of Experience in Teaching and Development using Microsoft Technologies. Since 1997, of the total 100000+ students Deccansoft has trained, he has personally trained over 60,000+ students and we are proud of him because almost every student he had trained is very happy with the quality and many are well placed in various I.T Firms.