Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if code is running on Azure Websites

Tags:

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.

like image 452
Gildor Avatar asked Sep 05 '14 04:09

Gildor


People also ask

How do I know if my Azure is running?

The best way I've come across to determine if you're running on an Azure Website is to check for the presence of an environment variable specific to Azure Websites like WEBSITE_SITE_NAME . You could check this first, and if the variable does not exist, proceed with the RoleEnvironment.

How do I monitor my Azure Web App?

Azure Monitor provides base-level infrastructure metrics and logs for most services in Azure. You can interact with the metrics in several ways, including charting them in Azure portal, accessing them through the REST API, or querying them using PowerShell or CLI.

How do I check application logs in Azure portal?

On the portal, click on “Log Stream” immediately below “App Services log” and you'll see the log messages in real time.

How do I check Azure logs?

We are able to generate the logs and they are in the path /home/logfiles/applications.


1 Answers

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

like image 178
Amit Apple Avatar answered Oct 18 '22 21:10

Amit Apple