ASP.NET Web API Self-Host with Windows Authentication

前端 未结 9 1308
不知归路
不知归路 2021-01-30 11:31

I am trying to use the ASP.NET Web API Self-Host option with Windows authentication so I can determine the logged on user and ultimately accept or reject the user based on their

9条回答
  •  轮回少年
    2021-01-30 12:20

    i have hosted "Web API" in windows service and this is what i did to support windows authentication (basically based on above question, answers, some related articles - i am just consolidating as it may be helpful for others)

    @HTTP Server (web api):

    Set (reference: http://msdn.microsoft.com/en-us/library/system.web.http.selfhost.httpselfhostconfiguration.clientcredentialtype(v=vs.118).aspx),

    HttpSelfHostConfiguration.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
    

    @Client:

    And then as Allan mentioned (above) set UseDefaultCredentials to true.

    Using HttpClient:

    var handler = new HttpClientHandler();
        handler.UseDefaultCredentials = true;
        _httpClient = new HttpClient(handler);
    

    Using WebClient (reference: http://msdn.microsoft.com/en-us/library/system.net.webclient.usedefaultcredentials.aspx )

    set webclient's usedefaultcrednetials to 'true'.

    Best Regards!

提交回复
热议问题