Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tor Langlo 191 posts 554 karma points
    May 07, 2019 @ 11:06
    Tor Langlo
    0

    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

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    May 07, 2019 @ 11:55
    Lee Kelleher
    0

    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

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    May 07, 2019 @ 11:56
    Lee Kelleher
    0

    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.

  • Tor Langlo 191 posts 554 karma points
    May 12, 2019 @ 13:04
    Tor Langlo
    0

    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

  • Tor Langlo 191 posts 554 karma points
    May 12, 2019 @ 13:05
    Tor Langlo
    0

    The environment file, is that one which you create manually? I haven't seen it on Local or on Dev env's.

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    May 13, 2019 @ 08:02
    Lee Kelleher
    0

    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

  • Tor Langlo 191 posts 554 karma points
    May 13, 2019 @ 08:14
    Tor Langlo
    0

    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?

    -Tor

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    May 13, 2019 @ 08:18
    Lee Kelleher
    1

    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)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies