thatuxguy
thatuxguy

Reputation: 2528

asp.net check if using local host

I would like to know how to check if i am using my localhost, or on the live server.

Basically i would like to have...

if (using localhost)
{
  Do Stuff...
}
else
{
   Do this instead...
}

How would i go about doing this? I have searched around but cant find anything. I would like to do this as i have different settings for the live and the dev servers. And i would like a way to automatically check to see what i am using, and then use certain settings.

Thanks in advance.

Upvotes: 4

Views: 7824

Answers (4)

Udaya Dananjaya
Udaya Dananjaya

Reputation: 1

This method facilitates easy identification of whether it's localhost or not, returning a Boolean value based on the host.

    public bool isLocal()
    {
        bool isLocal = false;
        HttpApplication http = new HttpApplication();
        if (http.Request.IsLocal)
        {
            isLocal = true;
        }
        return isLocal;
    }

Upvotes: 0

Alex Z
Alex Z

Reputation: 1442

if(HttpContext.Current.Request.IsLocal)
{
}

Upvotes: 5

J. Tanner
J. Tanner

Reputation: 575

Depending on whether you really need the check to be about the location, or about the build type, you might be interested in decorating the code with DEBUG checks.

See the following link.

http://msdn.microsoft.com/en-us/library/4y6tbswk(v=vs.100).aspx

#if DEBUG
 // Do stuff
#else
 // Do other stuff
#endif

Upvotes: 3

COLD TOLD
COLD TOLD

Reputation: 13579

you can try doing something like this

HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)

Upvotes: 18

Related Questions