在启用IIS身份验证的情况下访问Sitecore EE URL时,Invoke-WebRequest引发的访问由于凭据无效而被拒绝

问题描述

我试图在Powershell中获取Sitecore用户的StartUrl(在“配置文件”选项卡中配置),然后将其提供给Powershell中的Invoke-WebRequest以获取StartUrl的响应状态代码(以了解StartUrl是否为有效网址)

要访问StartUrl,必须在Sitecore应用程序中对用户进行身份验证。 我们还在IIS中启用了身份验证。因此,为了在浏览器中访问StartUrl,用户必须先向IIS进行身份验证,然后在Sitecore中进行身份验证(双重身份验证)。我们如何在Powershell中实现这一目标?我正在使用以下脚本,无法确定在何处提供Sitecore凭据

$IISuser = 'User'
$IISpass = 'Password!'
$pair = "$($IISuser):$($IISpass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
    Authorization = $basicAuthValue
}
$url = "https://mySitecoreInstance/?sc_mode=edit&sc_itemid=%7b50F6C3EC-CE89-4987-B0EF-5005938FE61D%7d&sc_site=website&sc_lang=en-US"
(Invoke-WebRequest $url -Headers $Headers).StatusCode

错误-

Invoke-WebRequest : Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
At line:11 char:2
+ (Invoke-WebRequest $url -Headers $Headers).StatusCode
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

如果$ url是Sitecore登录URL,而该脚本不需要Sitecore身份验证即可访问它,即$ url = https:// mySitecoreInstance / Sitecore / login

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)