实施 IReportServerCredentials 错误
我使用示例代码来实现 IReportServerCredentials 以发送登录信息以远程检索报告,但由于某种原因,该实现很容易出错。
Imports System.Net
Imports Microsoft.Reporting.WebForms
Imports System.Security.Principal
<Serializable()> _
Public NotInheritable Class ReportServerNetworkCredentials
Implements IReportServerCredentials
#Region "IReportServerCredentials Members"
''' <summary>
''' Specifies the user to impersonate when connecting to a report server.
''' </summary>
''' <value></value>
''' <returns>A WindowsIdentity object representing the user to impersonate.</returns>
Public ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
''' <summary>
''' Returns network credentials to be used for authentication with the report server.
''' </summary>
''' <value></value>
''' <returns>A NetworkCredentials object.</returns>
Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements IReportServerCredentials.NetworkCredentials
Get
dim userName As String = _
ConfigurationManager.AppSettings("MyReportViewerUser")
If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
Dim password As String = _
ConfigurationManager.AppSettings("MyReportViewerPassword")
If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
Dim domain As String = _
ConfigurationManager.AppSettings("MyReportViewerDomain")
If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End If
Return New System.Net.NetworkCredential(userName, password, domain)
End Get
End Property
''' <summary>
''' Provides forms authentication to be used to connect to the report server.
''' </summary>
''' <param name="authCookie">A Report Server authentication cookie.</param>
''' <param name="userName">The name of the user.</param>
''' <param name="password">The password of the user.</param>
''' <param name="authority">The authority to use when authenticating the user, such as a Microsoft Windows domain.</param>
''' <returns></returns>
Public Function GetFormsCredentials(ByVal authCookie As System.Net.Cookie, ByVal userName As String, ByVal password As String, ByVal authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
Return False
End Function
#End Region
End Class
类声明上有一个错误行
Implements IReportServerCredentials
,它表示类必须实现函数 getformscredentials....for 接口 microsoft.reporting.webforms.ireportservercredentials...
现在,当我相应地更改函数时,它仍然给出同样的错误。
I took sample code to implement the IReportServerCredentials to send the login information to retrieve a report remotely but for some reason the implementation is error prone.
Imports System.Net
Imports Microsoft.Reporting.WebForms
Imports System.Security.Principal
<Serializable()> _
Public NotInheritable Class ReportServerNetworkCredentials
Implements IReportServerCredentials
#Region "IReportServerCredentials Members"
''' <summary>
''' Specifies the user to impersonate when connecting to a report server.
''' </summary>
''' <value></value>
''' <returns>A WindowsIdentity object representing the user to impersonate.</returns>
Public ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
''' <summary>
''' Returns network credentials to be used for authentication with the report server.
''' </summary>
''' <value></value>
''' <returns>A NetworkCredentials object.</returns>
Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements IReportServerCredentials.NetworkCredentials
Get
dim userName As String = _
ConfigurationManager.AppSettings("MyReportViewerUser")
If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
Dim password As String = _
ConfigurationManager.AppSettings("MyReportViewerPassword")
If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
Dim domain As String = _
ConfigurationManager.AppSettings("MyReportViewerDomain")
If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End If
Return New System.Net.NetworkCredential(userName, password, domain)
End Get
End Property
''' <summary>
''' Provides forms authentication to be used to connect to the report server.
''' </summary>
''' <param name="authCookie">A Report Server authentication cookie.</param>
''' <param name="userName">The name of the user.</param>
''' <param name="password">The password of the user.</param>
''' <param name="authority">The authority to use when authenticating the user, such as a Microsoft Windows domain.</param>
''' <returns></returns>
Public Function GetFormsCredentials(ByVal authCookie As System.Net.Cookie, ByVal userName As String, ByVal password As String, ByVal authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
Return False
End Function
#End Region
End Class
on the class declaration there is an error line for
Implements IReportServerCredentials
and it says class must implement function getformscredentials....for interface microsoft.reporting.webforms.ireportservercredentials...
Now when I change the function accordingly it still gives the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设这是完整的错误消息:
在 MSDN 文档的语法部分中 IReportServerCredentials.GetFormsCredentials 您会看到声明的示例代码。
您的函数声明缺少 ByRef 关键字和每个参数的 OutAttribute。 ByRef 属性告诉 VB.NET 编译器将参数的值传递回调用者。 OutAttribute 告诉编译器构建调用代码,它不需要在传入参数之前初始化参数。您可以从 Directional Attributes MSDN 上的文章以及 Lasse V. Karlsen 关于 StackOverflow 关于属性 。
OutAttribute 是在 System.Runtime.InteropServices 命名空间中声明的,因此您需要在文件顶部添加此 Import 语句。
你的函数应该看起来更像这样:
I am assuming that this is the full error message:
In the Syntax section of the MSDN docs for IReportServerCredentials.GetFormsCredentials you see this sample code for the declaration.
Your funciton declaration is missing the ByRef keyword and the OutAttribute on each parameter. The ByRef attribute tells the VB.NET compiler to pass the parameter's value back out to the caller. The OutAttribute tells the compiler building the calling code that it does not need to initialize the parameter before passing it in. You can find more information about out parameters from the Directional Attributes article on MSDN as well as this helpful response from Lasse V. Karlsen on a StackOverflow question about the <Out()> attribute.
The OutAttribute is declared in the System.Runtime.InteropServices namespace, so you will need this Import statement at the top of your file.
Your function should look more like this: