确定是否ASP.NET应用程序在本地运行应用程序、ASP、NET

2023-09-03 09:26:17 作者:﹌ 那爱恐怕离不开

我想知道是否有如果ASP应用程序是在本地运行确定一个推荐的方法。目前我使用Request对象,做一个字符串搜索本地主机或127.0.0.1的服务器变量,但是这有一些限制。最大的一个是该请求对象并不总​​是可用的,当我需要它。

I want to know if there is a recommended way of determining if an asp application is running locally. At the moment I use the Request object and do a string search for localhost or 127.0.0.1 on the server variable but this has several limitations. The biggest one being that the Request object is not always available when I need it.

推荐答案

请参阅Htt$p$pquest.IsLocal

bool isLocal = HttpContext.Current.Request.IsLocal;