1

I have an ASP:NET web project with a simple HTTPHandler which filters out requests from outside IPs. The code itself works, but the HTTPHandler prevents my page from loading. No error. No infinite load. There's just a blank page.

If I remove the reference in the config, it loads perfectly fine. It's definitely caused by the HTTPHandler. I've also stepped through the handler and the code is definitely reached, it's just that when the handler is done, the page doesn't load like it should.

Here is the code.

public class SecurityHttpHandler : IHttpHandler
{
    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        string ipAddress = context.Request.UserHostAddress;
        if (!IsValidIpAddress(ipAddress))
        {
            context.Response.StatusCode = 403; 
        }
    }

    private bool IsValidIpAddress(string ipAddress)
    {
        return true; //for the time being, this will always return true
    }

    public void Dispose() {  } //clean
}

The handler exists in another project (i have a reference to the assembly) and the httphandler is registered in my webprojects web.config as such:

    <handlers>
        <add name="SecurityHttpHandler" verb="*" 
        path="*Default.aspx" 
        type="MyProjects.CommonResources.Web.SecurityHttpHandler" 
        resourceType="Unspecified" />
    </handlers>

I'm running IIS 7.5 in integrated mode. .net framework 4.0.

Here's what the blank page looks like:

Let me know if I should add more code. I excluded the code from my web-project as the handler itself seems to be the cause early in the asp.net pipeline.

user1531921
  • 1,372
  • 4
  • 18
  • 36
  • One the request is routed to your handler then it stays there, it doesn't then go to your page afterwards this is how handlers work, it looks like you are trying to use a handler for the wrong thing. Why not just put your IP address check in a base page that your other pages inherit from? – Ben Robinson Nov 25 '14 at 11:00
  • It seems like handlers and modeuls are used for just this. http://www.codeproject.com/Articles/16384/Using-ASP-NET-HTTP-Modules-to-restrict-access-by-I – user1531921 Nov 25 '14 at 11:27
  • Modules and handlers are totally different. – Ben Robinson Nov 25 '14 at 11:28
  • I thought the only difference was that a module covers the entire project whereas the handler is for a specific page. – user1531921 Nov 25 '14 at 11:33
  • This is what lead me to use a handler instead of a module: http://stackoverflow.com/questions/70956/exclude-certain-pages-from-using-a-httpmodule – user1531921 Nov 25 '14 at 12:05
  • Yes, but an IHttpHandler is the endpoint for your request. There is nothing more to process. You have to use a HttpModule instead with your filtering logic. – Stefan Ossendorf Nov 26 '14 at 21:49

0 Answers0