Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6551903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:23:41+00:00 2026-05-25T12:23:41+00:00

I have a worker role in my hosted service. The worker is sending e-mail

  • 0

I have a worker role in my hosted service.
The worker is sending e-mail daily bases.
But in the hosted service, there are 2 environment, Staging and Production.
So my worker role sends e-mail 2 times everyday.
I’d like to know how to detect if the worker is in stagning or production.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:23:42+00:00Added an answer on May 25, 2026 at 12:23 pm

    As per my question here, you’ll see that there is no fast way of doing this. Also, unless you really know what you are doing, I strongly suggest you not do this.

    However, if you want to, you can use a really nice library (Azure Service Management via C#) although we did have some trouble with WCF using it.

    Here’s a quick sample on how to do it (note, you need to include the management certificate as a resource in your code & deploy it to Azure):

     private static bool IsStaging()
            {
                try
                {
                    if (!CloudEnvironment.IsAvailable)
                        return false;
    
                    const string certName = "AzureManagement.pfx";
                    const string password = "Pa$$w0rd";
    
                    // load certificate
                    var manifestResourceStream = typeof(ProjectContext).Assembly.GetManifestResourceStream(certName);
                    if (manifestResourceStream == null)
                    {
                        // should we panic?
                        return true;
                    }
    
                    var bytes = new byte[manifestResourceStream.Length];
                    manifestResourceStream.Read(bytes, 0, bytes.Length);
    
                    var cert = new X509Certificate2(bytes, password);
    
                    var serviceManagementChannel = Microsoft.Toolkit.WindowsAzure.ServiceManagement.ServiceManagementHelper.
                        CreateServiceManagementChannel("WindowsAzureServiceManagement", cert);
    
                    using (new OperationContextScope((IContextChannel)serviceManagementChannel))
                    {
                        var hostedServices =
                            serviceManagementChannel.ListHostedServices(WellKnownConfiguration.General.SubscriptionId);
    
                        // because we don't know the name of the hosted service, we'll do something really wasteful
                        // and iterate
                        foreach (var hostedService in hostedServices)
                        {
                            var ad =
                                serviceManagementChannel.GetHostedServiceWithDetails(
                                    WellKnownConfiguration.General.SubscriptionId,
                                    hostedService.ServiceName, true);
    
                            var deployment =
                                ad.Deployments.Where(
                                    x => x.PrivateID == Zebra.Framework.Azure.CloudEnvironment.CurrentRoleInstanceId).
                                    FirstOrDefault
                                    ();
    
                            if (deployment != null)
                            {
                                return deployment.DeploymentSlot.ToLower().Equals("staging");
                            }
                        }
                    }
    
                    return false;
                }
                catch (Exception e)
                {
                    // if something went wrong, let's not panic
                    TraceManager.AzureFrameworkTraceSource.TraceData(System.Diagnostics.TraceEventType.Error, "Exception", e);
                    return false;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already have a hosted service deployment which has 2 worker role instances, I
I have a web service hosted on azure as a web role. In this
I have a worker role that works perfectly in development but doesn't work when
In my service i have. 1. A Worker Role. 2.A Web Role with input
in my service deployment i have two roles.. a web role and a worker
I have a working WCF service and worker role that I have been debugging
I have some code that I use in both my Worker Role and Web
I have a worker role monitoring a queue. As much as I would like
I have a simple video encoding worker role that pulls messages from a queue
I have been working on implementing a (1) server, (n) worker role servers setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.