tags:

views:

95

answers:

5

Is there a way to do this at runtime?

A: 

You could check and see if it's being hosted not on port 80 (since the dev server will by default give you a rather random port number)

TheTXI
By default this might work, but you can have IIS run on any port you want in a pinch.
Wyatt Barnett
+4  A: 

The standard server variables associated with IIS (INSTANCE_ID, INSTANCE_META_PATH), and SERVER_SOFTWARE all appear to be empty when examined from apps running on the ASP.NET Development Server. I would suggest examining their contents via Request.ServerVariables["SERVER_SOFTWARE"] or similar.

Jason Musgrove
A: 

Since I always compile my code for "Release" to normal servers and "Debug" for local code building, I always take advantage of

#if DEBUG
  //Some code that only happens in debug mode
#else
  //Production code (frequently connection strings)
#endif

Of course, if you forget to switch to "Release" mode when you publish, it's bad news :)

JustLoren
A: 

a bit indirect: HttpContext.Current.Request.IsLocal

Jim
A: 

If you are accessing it from a different machine it can't be the ASP.NET Development Server ("Casini")

Andrei Rinea