HttpListener: how to get http user and password?

后端 未结 3 1205
执笔经年
执笔经年 2021-02-19 18:02

I\'m facing a problem here, with HttpListener.

When a request of the form

http://user:password@example.com/

is made, how can I get the

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 18:56

    You need to first enable Basic Authentication:

    listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
    

    Then in your ProcessRequest method you could get username and password:

    if (context.User.Identity.IsAuthenticated)
    {
        var identity = (HttpListenerBasicIdentity)context.User.Identity;
        Console.WriteLine(identity.Name);
        Console.WriteLine(identity.Password);
    }
    

提交回复
热议问题