Is there a way to know in what environment my webrole runs? - azure

I am working on azure webrole, and in one of my application which is console application, I want to know in which enviroment my webrole running?
I.e staging / production environment.
Is there any dll available to get this idea? I am looking for the solution available with
dll provided by azure, not the REST API?
I want to do without the user of CERTIFICATE

check back this question.
There is no other way (that I know) to get the environment type.

Another good approach is given here
...you can check your application url, if its what your service name is then its production, othrwise if its some random guid then staging.

Related

PowerShell Scripts to run on Azure Web App, is it possible?

I have created a Function App which hosts PowerShell scripts and its main purpose is to add new users to Azure AD.
I want to get this onto a Web App with a simple GUI such as; First Name, Sure name, and E-mail address and a submit button.
I want to know what the simplest way to achieve this would be? And if it is possible to do.
Thank you for your help!
You could use an Azure Static WebApp to host your form and then have it call the Azure Function to submit the form.
Azure statis webapp docs here:
https://learn.microsoft.com/en-us/azure/static-web-apps/getting-started?tabs=vanilla-javascript
Adding an API here:
https://learn.microsoft.com/en-us/azure/static-web-apps/add-api?tabs=vanilla-javascript
Granted this is all in javascript but the front end would need to be in html/js anyway.
Other alternatives are something like PowerShell Universal if you wanted everything to be in PowerShell.
https://ironmansoftware.com/powershell-universal
I've heard good things about it but never actually used it myself

How to check if code is running on Azure Websites

I knew that we can use RoleEnvironment.IsAvailable to check if code is running in Web/Worker Role. How about Azure Websites?
I tried the above RoleEnvironment code but it always returns false. I need to run some configuration code in Application_Start so I cannot depend on the request stuff.
Any help is appreciated.
This is actually very easy simply check for existence of this environment variable: WEBSITE_SITE_NAME.
!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))
The content for this will be the name of your site.
To see more environment variable that you have under your site go to the following link: https://{sitename}.scm.azurewebsites.net/Env
You cannot (easily).
With azure Web Sites, your site runs in an IIS. RoleEnvironment will always be false, because it is not initialized there. Look at Azure Web Sites more like a regular hosting. Can you tell if your website is running in XYZ Hosting, or in your own IIS?
One thing that you could consider is the Application Settings in your web.config (yes, the appSettings section) and have some setting indicating whether you run on WebSites or not. Read the full article here about App Settings in Azure WebSites to understand what I mean. In short: if you set a setting value via the portal, it will take precedence over what is in web.config. You can even just set it in the Portal, not having it in your web.config.

How can an Azure website determine which region it is running in?

I will be placing an Azure website, in several regions. Then configuring the Azure Traffic Manager to distribute requests to each region.
The website needs to know which region it is running in. Is there an API available to determine this? Or, is my only choice, to define a REGION app setting, that is set appropriately for each Azure website?
I had the same question today, and found this thread. It seems that Web Apps now do include the promised environment variable showing the region in which they are deployed.
I simply used:
string region = Environment.GetEnvironmentVariable("REGION_NAME");
and it worked fine (note that it returns null when run outside Azure e.g. in Visual Studio).
I got a response, to my question, on the Microsoft Azure DNS and Traffic Manager forum.
The answer was:
There's no handy way currently. In the Azure Powershell, you could use Get-AzureWebsite to read the WebSpace value, which is structured as Region+"webspace".
For now it's easier to just add it to the app setting, like you suggested. We'll have the region value as an environment variable in a later release.
So, as suggested, we will just use an app setting to tell the website what region it is running in. We will switch over, to the environment variable, when it becomes available.

Is it possible to update configuration settings programmatically?

We are experimenting with deploying an MVC app as an Azure web role. Currently the app is being hosted locally on our server. It has a few appSettings in Web.Config that can be changed by the users as part of the "Administration" module of the application.
I know this isn't a good practice for Azure because there will potentially be multiple instances of the application running with multiple Web.Configs, which makes updating them all a nightmare (if not impossible). My understanding is that the ConfigurationSettings specified in the service definition should be used instead of Web.Config so that settings are defined globally in one place that all the instances of the application can access.
My question is is it possible to programmatically update ConfigurationSettings similar to the way we update Web.Config settings, or would it be better for us to move those settings into a database or something else?
Yes, but unfortunately it is definitely not simple to do.
Follow this URL: http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx
It talks about a Svc Management API call that you can make to read/write the Service Configuration. It is a 64-base string which you'll need to decode, find XML flags in it that you want to change and re-encode it back and send it back to the API.
Not pleasant, but doable.

How do I configure the locale and language of Azure Web Role?

How do I configure Azure Web Role to have United Kingdom (as opposed to US) as it's language/regional settings etc for all accounts? I believe I can RDP in and change it. However I want to set it to default on creation of the web role. It is making a difference to some classic ASP pages we have in a legacy app.
Interesting problem. Can't say I've attempted this before. What you want is to set a different locale at startup so that it is always enforced as VMs making up your Web Role may be rebooted from time to time.
Unless someone comes up with a better idea you could try to modify the registry from a Windows Azure Startup Task. You would need to know which user locale to modify and you would need a registry changing CmdLet like this one (though I haven't tried it): Set-RegistryKey.
Given you can figure out what registry value to modify and what user is running your IIS this could be done.
Use a Startup Task. Call a Cmd script and envoke a PowerShell script. Call the CmdLet and set the locale you want.
I realize this is not a complete solution, just a suggestion. Hopefully it is worth while.

Resources