HttpListener Digest Auth schema

我必须实现一个小型REST服务器来管理远程数据库,没什么特别的。 安全性不是关键问题,因为此服务器必须在Intranet环境中运行;我们只想过滤用户并将其重定向到适当的资源。
        HttpListener listener = new HttpListener();
        listener.Realm = "testserver1";
        listener.AuthenticationSchemes = AuthenticationSchemes.Basic;

        foreach (string s in prefixes)
        {
            listener.Prefixes.Add(s);
        }

        listener.Start();
        Console.WriteLine("Listening...");

        HttpListenerContext context = listener.GetContext();

        HttpListenerRequest request = context.Request;
        HttpListenerResponse response = context.Response;

        string responseString = "<HTML><BODY>" + DateTime.Now.ToString() + "</BODY></HTML>";
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);

        response.ContentLength64 = buffer.Length;
        System.IO.Stream output = response.OutputStream;
        output.Write(buffer, 0, buffer.Length);
        output.Close();

        listener.Stop();
此代码(取自Microsoft站点)在服务器端完美运行,并且当listener.GetContext()返回时 - 我可以检查User对象的用户名和密码,并确定如何处理请求。 更改初始侦听器.AuthenticationSchemes = AuthenticationSchemes.Basic to
listener.AuthenticationSchemes = AuthenticationSchemes.Digest
它停止工作,因为我期望和基本身份验证架构有效地做。 listener.GetContext()调用永远不会返回。 HttpListener SEEMS阻止任何请求,并且从客户端,我继续被提示输入用户名和密码。 我尝试过本地用户,本地管理员,域用户,域名管理员,大约500个幻想名称:没有用。 GetContext()不再返回。 你能帮助我吗? 提前致谢。 L.     
已邀请:
您可以使用AuthenticationSchemeSelectorDelegate,为我工作。例:
_listener.AuthenticationSchemeSelectorDelegate = delegate(HttpListenerRequest request)
{
    string temp = request.Headers["Authorization"];
    if (!string.IsNullOrEmpty(temp))
        throw new Exception("Auth string: " + temp);
    return AuthenticationSchemes.Digest; // here where you return auth type for every request eg. can be Basic,Digest
};
http://msdn.microsoft.com/en-us/library/system.net.httplistener.authenticationschemeselectordelegate.aspx     
分配给
listener.Realm
的值必须是用于身份验证的Windows域的名称。 “testserver1”看起来不像是域名。     

要回复问题请先登录注册