Articles → MICROSOFT AZURE → Configure app service with virtual networks in Azure

Configure app service with virtual networks in Azure






Scenario































Create an app service






Picture showing a screen for creating the web app in Azure

Click to Enlarge


Create a virtual network




Picture showing a virtual network with 2 subnets

Click to Enlarge


Configure virtual network on the app service




Picture showing the click here to configure link to configure virtual network on the app service

Click to Enlarge



Picture showing the Add Vnet button for adding the virtual network to the app service

Click to Enlarge



Picture showing a screen for adding virtual network

Click to Enlarge


Create a virtual machine to host the database server




Picture showing selecting the virtual machine as the database server

Click to Enlarge



Picture showing selecting the virtual network and subnet for the virtual machine

Click to Enlarge



Picture showing setting up the credentials for sql server in the virtual machine

Click to Enlarge


Create a database and tables




Picture showing the category table with data

Click to Enlarge


Disassociate public IP address from virtual machine




Picture showing a screen for disassociating public IP address from the virtual machine

Click to Enlarge


Write code to access the database






<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
	<div class="jumbotron">
		<h1>ASP.NET</h1>
		<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.</p>
		<p>
			<a href="http://www.asp.net" class="btn btn-primary btn-lg">Learn more »</a>
		</p>
	</div>
	<asp:GridView ID="gvData" runat="server"></asp:GridView>
</asp:Content>




using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;

namespace WebApplication1 {
  public partial class _Default: Page {
    protected void Page_Load(object sender, EventArgs e) {
      if (!IsPostBack) {
        string connectionString = "Data Source=10.0.1.4;Initial Catalog=mydatabase;User Id=demouser;Password=AdminPassword@123";
        DataTable table = new DataTable();
        using(SqlConnection connection = new SqlConnection(connectionString)) {
          using(SqlCommand command = new SqlCommand("select * from category", connection)) {
            using(SqlDataAdapter adapter = new SqlDataAdapter(command)) {
              adapter.Fill(table);

              gvData.DataSource = table;
              gvData.DataBind();
            }
          }
        }
      }
    }
  }
}



Publish app service




Picture showing the published app service with gridview binded with the data

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, May 14, 2021

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250