Coder Social home page Coder Social logo

ramm1997 / app-service-web-dotnet-manage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/app-service-web-dotnet-manage

0.0 0.0 0.0 11 KB

This sample demonstrates how to manage your WebApps using the .NET SDK

License: MIT License

C# 100.00%

app-service-web-dotnet-manage's Introduction

services platforms author
app-service
dotnet
devigned

Manage your web apps with the .NET SDK for Azure

This sample demonstrates how to manage your WebApps using the .NET SDK

On this page

Run this sample

  1. If you don't have it, install the .NET Core SDK.

  2. Clone the repository.

    git clone https://github.com/Azure-Samples/app-service-web-dotnet-manage.git
    
  3. Install the dependencies.

    dotnet restore
    
  4. Create an Azure service principal either through Azure CLI, PowerShell or the portal.

  5. Add these environment variables to your .env file using your subscription id and the tenant id, client id and client secret from the service principle that you created.

    export AZURE_TENANT_ID={your tenant id}
    export AZURE_CLIENT_ID={your client or application id}
    export AZURE_CLIENT_SECRET={your service principal secret}
    export AZURE_SUBSCRIPTION_ID={your subscription id}
    
  6. Run the sample.

    dotnet run
    

What does Program.cs do?

Main() gets the environment variables that you set up for this sample and calls RunSample. RunSample starts by setting up a WebSiteManagementClient using those credentials.

// Build the service credentials and Azure Resource Manager clients
var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, secret);
var resourceClient = new ResourceManagementClient(serviceCreds);
resourceClient.SubscriptionId = subscriptionId;
var webClient = new WebSiteManagementClient(serviceCreds);
webClient.SubscriptionId = subscriptionId;

The sample then sets up a resource group in which it will create the website.

Random r = new Random();
int postfix = r.Next(0, 1000000);

var resourceGroupName = "sample-dotnet-app-service-group";
var westus = "westus";
var serverFarmName = "sample-server-farm";
var siteName = "sample-site-name-" + postfix;

// Create the resource group
Write("Creating resource group: {0}", westus);
resourceClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = westus});

Create a server farm

Create a server farm to host the website.

var serverFarm = webClient.ServerFarms.CreateOrUpdateServerFarm(resourceGroupName, serverFarmName, new ServerFarmWithRichSku{
    Location = westus,
    Sku = new SkuDescription{
        Name = "S1",
        Capacity = 1,
        Tier = "Standard"
    }
});

Create a website

var site = webClient.Sites.CreateOrUpdateSite(resourceGroupName, siteName, new Site{
    Location = westus,
    ServerFarmId = serverFarm.Id
});

Get details for the given website

var gotSite = webClient.Sites.GetSite(resourceGroupName, siteName);

Delete a website

webClient.Sites.DeleteSite(resourceGroupName, siteName);

More information

Please refer to Azure SDK for .NET for more information.

app-service-web-dotnet-manage's People

Contributors

allclark avatar acomsmpbot avatar devigned avatar ramm1997 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.