我遇到了与 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 为空而出现错误,由于未启用自定义安全异常也出现错误
任何解决方案/帮助都将不胜感激
附加从 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;
}