Ultimately, there's a text file called environment, which is in the parent directory of the website. That contains the name of the current environment.
All the other code in my repo is based around that.
I don't have a file named C:\home\site\environment, but I do have a folder with that name. Inside that folder there's a file named either development or live dependent on which environment I'm in. Is that what you mean?
Detect current environment
Hi,
Is there a property or method which will tell me which Umbraco Cloud environment I'm currently on?
I know I can inspect the url of the current request, etc., but if there's something built in I'd rather use that.
-Tor
Hi Tor,
I have code that I use on my own Umbraco Cloud projects, which I started to put together into a package, but never released it.
The code is here: https://github.com/leekelleher/umbraco-cloud-toolkit.
Take whatever code you want from the repo.
There are some MVC view helper methods, e.g.
@Umbraco.IsStaging()
https://github.com/leekelleher/umbraco-cloud-toolkit/blob/develop/src/Our.Umbraco.Cloud.Toolkit/Extensions/UmbracoHelperExtensions.cs
or an
EnvironmentHelper
utility class if needed elsewhere.https://github.com/leekelleher/umbraco-cloud-toolkit/blob/develop/src/Our.Umbraco.Cloud.Toolkit/Helpers/EnvironmentHelper.cs#L9
Hope this helps.
Cheers,
- Lee
Ultimately, there's a text file called
environment
, which is in the parent directory of the website. That contains the name of the current environment.All the other code in my repo is based around that.
Thanks Lee! I also developed my own simple solution, but will take a closer look at the repo since there seems to be a bit more of value there.
-Tor
The environment file, is that one which you create manually? I haven't seen it on Local or on Dev env's.
Hi Tor,
The file will already exist on the environment. If you have access to the Kudu console, the text file will be in
C:\home\site\environment
.As for Local, that file doesn't exist - the code in my repo will make some assumptions, e.g. using
HttpContext.Request.IsLocal
.Otherwise it assumes it's "Elsewhere" (wherever that may be) :-D
Cheers,
- Lee
I don't have a file named
C:\home\site\environment
, but I do have a folder with that name. Inside that folder there's a file named eitherdevelopment
orlive
dependent on which environment I'm in. Is that what you mean?-Tor
Yup, that's the one! :-D (I'd forgot it was a folder when I replied last week - it's been a while since I'd looked at it)
is working on a reply...