The HttpContext.IsDebuggingEnabled
property:
using System.Web;
if (HttpContext.Current.IsDebuggingEnabled) { /* ... */ }
From the documentation:
Gets a value indicating whether the current HTTP request is in debug mode[…]
true
if the request is in debug mode; otherwise,false
.