Search code examples
c#asp.nethttphandler

Is localhost safe to check as a security condition


I have an HttpHandler that does something but I want don't want it to run when running on my local machine. For now, I simply comment out the handler in the web.config file when I'm running the site in Visual Studio, and uncomment it when I deploy the site: cumbersome. I want to add a condition to check if the site is running on my local machine like this:

public void ProcessRequest(HttpContext context)
{
    if (context.Current.Request.Url.Host != "localhost") { DoSomething(); }
}

Is this safe or is it possible that when I deploy the condition will not trigger?


Solution

  • Instead I'd recommend you use:

    HttpContext.Current.Request.IsLocal