asp.net HTTPHandler prevents page from loading

佐手、 提交于 2019-12-13 05:29:48

问题


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.

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.

来源:https://stackoverflow.com/questions/27124737/asp-net-httphandler-prevents-page-from-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!