在.Net中强制URL的特定SPN

时间:2016-09-28 07:23:47

标签: c# .net powershell kerberos integrated-security

使用.Net框架(C#和Powershell)访问Kerberized HTTP服务时,我遇到了不一致的行为。它与我们的DNS配置以及我们对 CNAME 的使用有关,而不是对Kerberized服务使用A记录。 Microsoft建议的解决方法是确保您为主机名使用A记录,但这不是我公司环境中的选项。

我需要一个解决方案,允许我为特定的URL强制使用特定的SPN,确保我为SPN使用与URL相同的主机名。或者,可以选择强制使用一致的策略将URL解析为SPN。

1 个答案:

答案 0 :(得分:1)

与往常一样,一旦您知道自己在寻找什么,解决方案就很容易找到;-)在这个例子中,我在端口8080上使用HTTPS Web服务:

<强> C#:

[System.Net.AuthenticationManager]::CustomTargetNameDictionary.
    Add("https://my-service.tld:8080/", "HTTP/my-service.tld")

<强> Powershell的:

:8080

不要忘记尾随斜杠。如果使用端口80,请删除{ "details": [ { "outBound": [ { "info": { "date": "2016-08-11", "class": "M", "code": 70, "pricing": [ { "totalAmount": 68.8, "totalTaxAmount": 30.8, "baseFareAmount": 38.0 } ], "totalAmount": 68.8, "totalDuration": 160, "referenceNumber": 1, "type": "RP", "id": 1 }, "segments": [ { "date": "2016-08-11", "className": "Standard (W)", "code": 70, "totalAmount": 68.8, "totalDuration": 160, "referenceNumber": 1, "type": "RP", "duration": 160, "number": "100" } ] }, { "info": { "date": "2016-08-11", "class": "M", "code": 70, "pricing": [ { "totalAmount": 78.8, "totalTaxAmount": 40.8, "baseFareAmount": 38.0 } ], "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "id": 2, "gstAmount": { "taxType": "GST" }, }, "segments": [ { "date": "2016-08-11", "className": "Standard (W)", "code": 70, "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "duration": 160, "number": "200" }, { "date": "2016-08-11", "className": "Standard (W)", "code": 70, "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "duration": 160, "number": "100" } ] } ], "resultCount": { "count1": 1, "count2": 1 }, "displayCount": 2 } ] } >Expected Output: { "info": { "date": "2016-08-11", "class": "M", "code": 70, "pricing": [ { "totalAmount": 78.8, "totalTaxAmount": 40.8, "baseFareAmount": 38.0 } ], "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "id": 2, "gstAmount": { "taxType": "GST" }, }, "segments": [ { "date": "2016-08-11", "className": "Standard (W)", "code": 70, "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "duration": 160, "number": "200" }, { "date": "2016-08-11", "className": "Standard (W)", "code": 70, "totalAmount": 78.8, "totalDuration": 160, "referenceNumber": 2, "type": "RP", "duration": 160, "number": "100" } ] }

参考文献: