Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sometimes its helpful to know if the user visiting the website is coming from localhost or if debugging is enabled. For example, you might want to display debugging- or development-related information at the top of each web page, such as the time it took to execute the page or detailed information about the currently logged-in user. However, this information should not be shown to end users; rather, it should only be displayed if the user is visiting locally or if debugging is enabled.

The good news is that it's quite easy to determine whether a visitor has arrived at the site locally, thanks to the Request object's IsLocal property. Request.IsLocal returns True if the visitor is coming from localhost, False otherwise. To determine whether debugging is enabled, use the HttpContext object's IsDebuggingEnabled property.

The IsDebuggingEnabled property checks the value of the debug attribute of the compilation element in de web.config.
<compilation defaultLanguage="c#" debug="true"⁄>

The code snippet below shows how to display a Panel (pnlDiagnosticInfo) only if the user is arriving from localhost and debugging is enabled.

// C# 
if (Request.IsLocal && HttpContext.Current.IsDebuggingEnabled) 
   pnlDiagnosticInfo.Visible = true; 

 © Evident Interactive BV