Create an Azure Web App Using C# - c#

Hi I'm currently refreshing my knowledge in C# programming.
I wanted to translate the manual way of creating a Web App in Microsoft Azure (Classic) into the C# language.
(Manual way - New > Compute > Web App > Custom Create > ...etc.. )
Whenever I search through google about this topic all it gives me is to literally create a "WebApp" in Visual Studio. (File > New > ...etc...) However, what I am looking for is how to create an Azure Web App programatically via C# - how to interact with the Management UI of the Classic Azure Portal to create a web app.
Anyone familiar to do this? Thanks in advance for the help! :)

To create an azure website easily using C#, you can use "Windows Azure Management Libraries". This SDK is a wrapper arround "Azure Service Management" API.
Here is a introduction from Braddy Gaster an a blog post, to get credentials from an Azure Tenant an work with ASM Api.
Then you will be able to create a website with something like this :
using (var AwsManagement = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(azureCredentials))
{
WebSiteCreateParameters parameters = new WebSiteCreateParameters()
{
Name = "myAws",
// this Service Plan must be created before
ServerFarm = "myServiceplan",
};
await AwsManagement.WebSites.CreateAsync("myWebSpace", parameters, CancellationToken.None);
}

I was able to work on the available code Microsoft posted in GitHub:
https://github.com/Azure/azure-sdk-for-net
I re-coded some and just acquired the functions that I only need for my program to work. :)

You can create a web site by using a POST request that includes the name of the web site and other information in the request body. You can check the code example for ASM here.

Related

How to set Custom Base URL in Azure App Service with .Net Core?

I have created a web application in .Net core(v5.0) and hosted it in Azure App Service. I have created a view and that allows me to add a new URL based on that create a new subdomain in the same service and publish code in that. This concept also uses in Jira software where our <projectname>.atlassian.com
Eg:
I have added dev in a text box then-new subdomain added like. dev.<myappservicename>.azurewebsites.net
In this case, all code copy and run this code properly.
Main Domain:
Base URL(Created URL): <myappservicename>.azurewebsites.net
Custom URL(Added from View): dev.<myappservicename>.azurewebsites.net
,
admin.<myappservicename>.azurewebsites.net
Technology Specification:
.Net Core(5.0)
C#
Azure App Service
If anyone has an idea then suggest thought.
It helps me a lot.
You can use restapi or .net sdk to create subdomain.
From your description, I see that there should be no need to redeploy your webapp, so if there is a business need, it is recommended to identify it through the program, what is the input url of the browser, to process your program.
Eg:
company1.<projec_tname>.azurewebsites.net
Get HttpRequest url to handle company1's bussiness.
company2.<projec_tname>.azurewebsites.net
Get HttpRequest url to handle company2's bussiness.

Update dropdown list Google Forms with C#

I am using code to read information from Google Sheets (results from Google Forms) with C# but now I want to update a dropdown list for a specific Google forms with C#. I have seen code where you can update a dropdown list with google app script (https://developers.google.com/apps-script/reference/forms )but I can not find code to do this within C#. It is possible within C# to update a google sheet so you should think it is possible to do the same with Google Forms. Does anyone done this?
The example i have found is very simple within app script
var existingForm = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var item = form.getitembyid(3567489);
var values = ["oranges", "Tomatoes"]
item.asListItem().setChoicesValues(values);
There is no Forms API, so you cannot do this directly with C#. Because of this, the only option, if you want to do this programmatically, is using Apps Script.
There are workarounds, though, to "wrap" the Apps Script, and call it remotely from your C# program:
Workaround #1 (Apps Script Web App):
You could publish your script as a web app and use this as a URL endpoint that you will access with your C# application. The web app would receive the HTTP requests from your application, and edit the form. For example, you could do a POST request with data about the items you want to edit, and use the corresponding event object to retrieve that information. It could be something along these lines:
function doPost(e) {
var formId = e.parameter.id; // Your form id
var itemId = e.parameter.itemId; // Your item id
var form = FormApp.openById(formId);
var item = form.getItemById(itemId);
var values = e.parameters.values; // ["oranges", "Tomatoes"]
item.asListItem().setChoicesValues(values);
}
Workaround #2 (Apps Script API):
Another way, if you want to edit your form remotely from your C# application, is to use Apps Script API to create and run the Apps Script project that contains the code for editing the form. Beware, this is not an easy way, and it would take several steps:
Get access to the Form via OAuth 2.0.
Using this library, create a project with Apps Script API, by using the method projects.create. I'd suggest you to create a project that is bound to the Form, so that you don't need to authorize the script when it's time to execute it. If you do that, you would need to specify the parentId in your request body (and in your script you could use FormApp.getActiveForm() instead, which wouldn't require authorization).
Using the scriptId retrieved from the response in previous step, call projects.updateContent, in which you would have to add the code corresponding to the files in your project.
Call scripts.run to execute your code an update your form. If you have created a standalone script in step 2, you will have to authorize your project via OAuth 2.0.
Reference:
Apps Script Web Apps
Using OAuth 2.0 to Access Google APIs
Google Apps Script API
Apps Script API Client Library for .NET

Create Resource Group with Azure Management C# API

Is there a way to create a Resource Group with the Azure Management C# API?
Basically this REST API call:
https://msdn.microsoft.com/en-us/library/azure/dn790525.aspx
I found a way to create an Affinity Group by using client.AffinityGroups.Create, but that's the closest thing I've found.
I found the API call was hidden in a library which is only in preview mode at the moment. It's found in the following NuGet package, enable include prerelease in Visual Studio to find it in the NuGet client.
https://www.nuget.org/packages/Microsoft.Azure.Management.Resources/
Then to create a resource group I can use
var credentials = new TokenCloudCredentials("", "");
var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(credentials);
var result = c.ResourceGroups.CreateOrUpdateAsync("MyResourceGroup", new Microsoft.Azure.Management.Resources.Models.ResourceGroup("West US"), new System.Threading.CancellationToken()).Result;
There is another stack overflow post explaining how to do the authentication:
How to get Tags of Azure ResourceManagementClient object
The following blog post explains how to set up TokenCloudCredentials, required for the authentication part, in more detail, but only for command line apps:
http://www.bradygaster.com/post/using-windows-azure-active-directory-to-authenticate-the-management-libraries
If you want to use something other than a command line app the following can work for authentication:
http://www.dushyantgill.com/blog/2015/05/23/developers-guide-to-auth-with-azure-resource-manager-api/
Go to https://resources.azure.com - the ARMExplorer shows both the REST and the PowerShell commands to create a resource group. All the APIs are REST based. In C#, send a WebClient request.

How can I use Azure Mobile Services and SQL Azure StoredProc function in my WP 8.1 App for user registration page

I have been following the online tutorials provides on Azure and WP series. So far I have been able to understand flow of "TODO application" which is built.
I followed the guidelines provided and created my own WP 8.1 "User registration app". I have created the following in Azure.
Mobile Service
Database and required tables and required columns for this application
I have also written StoredProc which provides OUTPUT result upon success and failure.
When I tried to call this storedproc I was not able to access or to be more honest, I don't have any idea on how to call this or go about. I have been looking around places which were pointing to use "Mobile service API" then call the StoredProc function etc which made me more confused.
How to solve this?
What I need to achieve is, from the WP app I have written, the user key-in the required values, click on "register" button, the function should call Storedproc by passing all the values from WP app to StoredProc as parameter, upon successful execution of StoredProc, it returns a RESULT value which my application need to use and save a system generated value in WP isolated storage, so when next time application loads, it will check for this file, if available the application loads if not it will navigate the user to registration page.
I have been able to pull out sample on isolated storage and other stuff, but not able to achieve with respect to StoredProc and sending and receiving the data to and from Azure SQL Server.
Please help - Thanks in advance.
Depending on which sort of Mobile Services backend you have (Node or C#) you can invoke stored procedures using a pattern similar to the following:
function(request, response) {
var mssql = request.service.mssql;
mssql.query("EXEC <<your_sproc_name>> ?", request.query.<<your_query_prop_here>>, {
success: function(results) {
// console.log(results) <-- use for debugging
// return results (or pass to another function)
}
});
};
If this doesn't really answer the question fully it's worth looking at the Azure Mobile Services Custom APIs documentation which will cover this scenario in more detail.

Getting started Facebook API

i want to develop Desktop based application in wpf (c#). which will need option to login their facebook account too. so i have registered my app in fb developer site and download C# sdk with reference some stack overflow link. which always give connection failed
// code which i have used
string APIKey = ConfigurationManager.AppSettings["API_Key"];
string APISecret = ConfigurationManager.AppSettings["API_Secret"];
Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(APIKey, APISecret);
if (connectsession.IsConnected())
{
Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);
var friends = api.Friends.GetLists();
foreach (var friend in friends)
{
System.Console.WriteLine(friend.name);
}
}
some site telling that C# sdk is deprecated.
http://developers.facebook.com/blog/post/624/
Facebook Graph C# SDK Ver 6.0: Unable to create event on App's Page
please help me to start facebook api integration in my desktop based app using wpf. some body asked to use graph api but i have doubt whether this will supprot for c# . am struk to start my step on facebook integration.
Graph Api is fully supported in C# because it is based on rest and you can call rest service through C# code, obviously url calling is different from method calling, In graph api you can call url and parse its response. I would recommend to go with graph api, Facebook has not provided the C# SDK, its a open source library maintained by open source community, however graph api help is directly provided by Facebook.
Check here and here to know how to call graph api through C#

Categories

Resources