我在 Windows Server 2019 中遇到有關 SSRS(Sql Server Reporting Server) 2019 自訂安全性異常的問題。
SSRS 報告在 SQL Server 早期版本(2016、2014 和 2012)中的 winforms vb.net 程式碼中運作良好,但在 2019 年則不行。
使用 Vb.net Winforms 原始碼運行報告,並將 WebRequest 發送到 SSRS 伺服器,並提供必要的詳細信息,如伺服器 url、使用者名稱、密碼、DBName 等,使用 webResponse 返回回應需要獲取使用者的身份驗證 cookie
由於 sqlAuthCookie 為 null 而出現錯誤,並且由於未啟用自訂安全性異常而出現錯誤
任何解決方案/幫助將不勝感激
附上從 vb.net 發送並從 SSRS 伺服器取得回應的程式碼片段。
VB.NET Code
Protected Overrides Function GetWebResponse(ByVal request As WebRequest) As WebResponse
Dim response As WebResponse = MyBase.GetWebResponse(request)
Dim cookieName As String = response.Headers("RSAuthenticationHeader")
' If the response contains an auth header, store the cookie
If Not (cookieName Is Nothing) Then
Dim webResponse As HttpWebResponse = CType(response, HttpWebResponse)
Dim authCookie As Cookie = webResponse.Cookies(cookieName)
' If the auth cookie is null, throw an exception
If authCookie Is Nothing Then
Throw New Exception("Unable to generate report - the Reporting Services Custom Security Extension is expected to be enabled in XB")
End If
' otherwise save it for this request
Me.AuthCookie = authCookie
' and send it to the client
End If
Return response
End Function
//adding new GetUserInfo method for IAuthenticationExtension2
public void GetUserInfo(IRSRequestContext requestContext, out IIdentity userIdentity, out IntPtr userId)
{
userIdentity = null;
if (requestContext.User != null)
{
userIdentity = requestContext.User;
}
// initialize a pointer to the current user id to zero
userId = IntPtr.Zero;
}