c# - HttpListener 摘要身份验证架构

标签 c# httplistener digest-authentication

我必须实现一个小型 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 对象检查用户名和密码并确定如何处理请求. 将初始 listener.AuthenticationSchemes = AuthenticationSchemes.Basic 更改为

listener.AuthenticationSchemes = AuthenticationSchemes.Digest

它停止工作,正如我所期望的那样,并且 Basic auth schema 有效地工作。 listener.GetContext() 调用永远不会返回。 HttpListener SEEMS 阻止任何请求,并且从客户端继续提示我输入用户名和密码。 我已经尝试了本地用户、本地管理员、域用户、域管理员,大约 500 个幻想名称:没有任何作用。 GetContext() 不再返回。 你能帮帮我吗?

提前致谢。

L.

最佳答案

分配给 listener.Realm 的值必须是用于身份验证的 Windows 域的名称。 “testserver1”在我看来不像是域名。

关于c# - HttpListener 摘要身份验证架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5219293/

相关文章:

authentication - RTSP 身份验证 : digest issue

c# - 仅向 DbContext 添加数据一次

c# - 刷新 Windows 窗体中的 DataGridView

c# - 如何从 HttpListenerRequest 获取表单参数?

javascript - chrome 控制台显示带有摘要身份验证的密码

http - FLUTTER如何实现摘要认证

c# - 了解 C# WPF 中的文本范围

c# - 从子元素引用父元素的值

c# - 使用 HttpListener 的 Windows 桌面应用程序的 OAuth 2.0 授权

vb.net - 在 .NET 中解码基本授权的最简单方法