在httplisteners authenticationselectordelegate

时间:2019-05-08 09:06:01

标签: c# httplistener system.net

我目前正在使用httplistener authenticationselector委托进行Windows身份验证和ip检查,它的工作非常出色,因为它拒绝并允许应有的客户端。

但是,问题是当有人被拒绝时,他们会收到403 http响应,这似乎被大多数浏览器解释为黑屏。我想做的是发回一条消息,说“访问被拒绝:您的IP已被列入白名单”。

这可能吗?

下面是代表的摘要(目前可以正常运行)。

AuthenticationSchemeSelector pIPChecker = pRequest =>
{
    if (!pfunIPChecker(pRequest.RemoteEndPoint.Address))
    {
        LogHelper.writeToEventLog(
            "WARNING, BANNED IP: " + pRequest.RemoteEndPoint.Address.MapToIPv4().ToString() + "attempted to login", 
            EventLogEntryType.Warning,
            LogHelper.EventLogID.PermissionFailure);

        return AuthenticationSchemes.None;
    }

    return AuthenticationSchemes.Anonymous;
}

1 个答案:

答案 0 :(得分:0)

正如X39所指出的那样,唯一的方法似乎是来使用Authenticator委托,而是像往常一样实际读入请求,并发回包含您所要内容的403欲望。