Possible Duplicate:
How to check in ASP.NET MVC View if site is running on localhost or 127.0.0.1
I am using two entry for connection string in web.config, and i am using HttpContext.Current.Request.UserHostAddress for detection between deployment and development environment:
public static SqlConnection GetSqlConnection()
{
if (HttpContext.Current.Request.UserHostAddress != "127.0.0.1")
...
else
...
}
but problem is here, some times HttpContext.Current is null and raise exception (i.e: when scheduled task is runed in asp.net from global.asax).
is there any general solution for this?
You’re supposed to change the connection string in the configuration file between environments. That’s why they’re stored in a configuration file in the first place, so you wouldn’t have to do this.
I prefer to put connection strings in a separate file and not deploy it at all. The same can be done with other configuration that’s environment specific. Another way is to use an XML transform as a part of your build job to change the connection string when deploying into production.