首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加WWW-Authenticate标头时会出现错误

添加WWW-Authenticate标头时会出现错误
EN

Stack Overflow用户
提问于 2021-03-09 21:15:38
回答 1查看 141关注 0票数 0

我正在尝试在我的.NET HttpListener上配置基本访问授权,但我总是遇到相同的错误。我已经尝试了所有可以在这个网站和其他网站上找到的解决方案,但都没有成功。

我需要使用admin/admin作为基本身份验证的用户名/密码。wikipedi page显示了头部应该是什么样子,我遵循了这一点。

我一直收到错误消息“头WWW-Authenticate必须用正确的方法更改,参数:名称”,但是没有必须添加的名为"name“的参数,就像维基百科页面上显示的那样。不幸的是,我已经没有选择了,希望有人能帮上忙。

我的代码如下

代码语言:javascript
复制
private void WebRequestCallback(IAsyncResult result)
{
    if (httpListener == null)
    {
        return;
    }

    HttpListenerContext context = httpListener.EndGetContext(result);

    if (basicAccessAuth)
    {
        HttpListenerRequest Request = context.Request;
        HttpListenerResponse Response = context.Response;

        httpListener.AuthenticationSchemes = AuthenticationSchemes.Basic;
        NameValueCollection nvCol = new NameValueCollection();
        nvCol.Add("Authorization", "admin:admin");
        httpListener.Realm = "Overflow";

        Request.Headers.Add(nvCol); // error gets thrown here, missing "name" parameter
        Response.Headers.Add("WWW-Authenticate: Basic YWRtaW46YWRtaW4=");

        HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity;
        MessageBox.Show(identity.Name);
    }

    httpListener.BeginGetContext(new AsyncCallback(WebRequestCallback), httpListener);

    if (ReceiveWebRequest != null)
    {
        ReceiveWebRequest(context);
    }
    ProcessRequest(context);

}
EN

回答 1

Stack Overflow用户

发布于 2021-03-10 21:35:14

我已经解决了我的问题。我加错了头,应该是Response.AddHeader而不是Response.Headers.Add

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66547625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档