Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:35:23+00:00 2026-06-16T03:35:23+00:00

I have a list of IP’s that keep crawling our live site which throw

  • 0

I have a list of IP’s that keep crawling our live site which throw exceptions when they use certain URL’s with no parameters (because of the MVC routing). I want to block those IP addresses and return a 404 not found page as soon as they can be picked up, but I don’t want to do it in IIS as I want to log the encounters within our application.

I’ve written a catch-all type routehandler that uses a custom MvcHandler to check the list and modify the response:

public class ApplicationRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        BlacklistedIPAddressHandler handler = new BlacklistedIPAddressHandler(Cache.WebsiteCache.GetBlacklistedIPList(), requestContext);

        return handler;
    }
}

public class BlacklistedIPAddressHandler : MvcHandler
{
    List<IPBlacklistModel> blacklist;

    public BlacklistedIPAddressHandler(List<IPBlacklistModel> Blacklist, RequestContext requestContext) : base(requestContext)
    {
        blacklist = Blacklist;
    }

    protected override IAsyncResult BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, object state)
    {
        var ip = httpContext.Request.UserHostAddress;

        if (blacklist != null &&
            blacklist.Where(x => x.IP_ADDRESS.Contains(ip)).Count() > 0)
        {

            httpContext.Response.ClearHeaders();
            httpContext.Response.Clear();

            httpContext.Response.StatusCode = 404;
            httpContext.Response.SuppressContent = true;
            httpContext.Response.End();
        }

        return base.BeginProcessRequest(httpContext, callback, state);
    }
}

It’s then implemented as follows:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new { controller = @"[^\.]*" }
        ).RouteHandler = new Helpers.Routing.ApplicationRouteHandler();
    }

I keep getting a Server cannot append header after HTTP headers have been sent error when I do this. Anybody perhaps know why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:35:25+00:00Added an answer on June 16, 2026 at 3:35 am

    I suppose you should remove httpContext.Response.End(); statement from your handler – as the request is passed for further processing, it should not be terminated now.

    HttpResponse.End method description from MSDN:

    Sends all currently buffered output to the client, stops execution of
    the page, and raises the EndRequest event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of a an object which is termed as rule in our
I have list of textareas. For textareas I use tinyMCE Editor. When I start
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,
I have list of files which contain particular patterns, but those files have been
I have list of images. what i want that when user clicks on one
I have list (array list)that can contain many instances (between 500-3000 instances ). during
I have list of string which I want to add as option in select
I have list of restaurant details along with menus which i got from singleplatform.
I have list in which a column is of type Person or Group. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.