HttpContext.Current.Request.IsLocal does not work in Startup class

1

I'm trying to use HttpContext.Current.Request.IsLocal; in an application web api 2 in class Startup method Configuration(IAppBuilder app) .

The idea is to only upload a server hangfire if it is in production, I do not want to upload local.

The problem is that the server always comes with true , and this only happens in that class, I did a test routine on a controller and it worked, it returned false .

How would I know if it's local or not at this point in the system?

Here is the sample code:

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
          
          
          
          bool isLocal = HttpContext.Current.Request.IsLocal;
            if (isLocal == false) { 
                app.UseHangfireServer(boptions);
              
        }
          
     }
    
asked by anonymous 13.08.2015 / 16:25

1 answer

1

The Startup class is executed when the server goes up, and this is done by the own machine that the server is running.

This is why IsLocal will always return true ...

The IsLocal property returns true if the IP address of the originator request is 127.0 .0.1 or if the IP address of the request is the same as the server's IP address.

    
01.09.2015 / 20:53