问题
I'm migrating an web app from an Azure Cloud Services Web Role to Azure Websites. Websites can't find Microsoft.WindowsAzure.ServiceRuntime
and doesn't seem to like the Cloud Service helpers in general.
The app uses RoleEnvironment.IsAvailable
in a few places to behave differently online versus on a development computer. (We ran in development outside of the Web Role emulator for speed.)
Is there an equivalent property to RoleEnvironment.IsAvailable
for determining whether the app is running in the cloud?
回答1:
There are many ways to differentiate running on Azure Websites of in a development environment.
If it's in the context of a request then I would go with checking the host if it's localhost
vs mysite.com
for example.
Another option is to check any of the Environment Variables that Azure websites injects in your site. You can find a list in here https://<yourSiteName>.scm.azurewebsites.net/Env
Finally you can define your own AppSetting in Azure Portal for the site, then check it's existence to know which environment you are running on.
来源:https://stackoverflow.com/questions/28998566/azure-websites-roleenvironment-isavailable-equivalent