简体   繁体   English

asp.net检查是否使用本地主机

[英]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. 我想这样做,因为我对live和dev服务器有不同的设置。 And i would like a way to automatically check to see what i am using, and then use certain settings. 我想要一种自动检查以查看我正在使用的方法,然后使用某些设置。

Thanks in advance. 提前致谢。

you can try doing something like this 你可以尝试做这样的事情

HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)
if(HttpContext.Current.Request.IsLocal)
{
}

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. 根据您是否确实需要检查有关位置或构建类型,您可能有兴趣使用DEBUG检查来装饰代码。

See the following link. 请参阅以下链接。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM