ReportViewer中设置ServerReport.ReportServerCredentials属性的方法(WEB版)

当使用SSRS技术来布置报表,可能使用MS自带的ReportViewer控件来读取报表.

它分为Web和Windows两种版本;此处Web版.


ServerReport.ReportServerCredentials属性的类型为Microsoft.Reporting.WebForms.IReportServerCredentials,它可提供三种认证方式所需的证书(Credential):

 1) Form认证证书(GetFormsCredentials);

 2) 扮演认证证书(ImpersonationUser);

 3) 网络认证证书(NetworkCredentials).

 

 当报表的服务器端使用网络认证时,需要实现NetworkCredentials接口,而且必须将GetFormsCredentials()接口的返回值设置为False,否则会导致论证失败.

 示例代码如下:

 

代码
 1     '''   <summary>
 2       '''  Initialize report viewer
 3       '''   </summary>
 4       '''   <remarks> Viewer是ReportViewer的一个实例 </remarks>
 5       Protected   Overridable   Sub  LoadReportViewer()
 6           With  Viewer
 7              .Visible  =   True
 8              .ProcessingMode  =  Microsoft.Reporting.WebForms.ProcessingMode.Remote
 9              .ServerReport.ReportServerUrl  =   New  Uri( < 报表服务器的URL > )
10              .ServerReport.ReportPath  =   < 报表相对于ReportServerUrl的路径 >
11              .ServerReport.ReportServerCredentials  =   < IReportServerCredentials的实例 >
12              .ShowParameterPrompts  =   False
13           End   With
14       End Sub
15 
16 
17      '''   <summary>
18       '''  Internal implementation for report server credentails.
19       '''   </summary>
20       '''   <remarks></remarks>
21       Public   Class  ReportServerCredentials
22           Implements  IReportServerCredentials
23 
24           Private  _Domain  As   String
25           Private  _Password  As   String
26           Private  _UserName  As   String
27 
28           Public   Sub   New ()
29               Me .New( Nothing Nothing Nothing )
30           End Sub
31 
32           Public   Sub   New ( ByVal  userName  As   String ByVal  password  As   String )
33               Me .New(userName, password,  Nothing )
34           End Sub
35 
36           Public   Sub   New ( ByVal  userName  As   String ByVal  password  As   String ByVal  domain  As   String )
37              _UserName  =  userName
38              _Password  =  password
39              _Domain  =  domain
40           End Sub
41 
42           Public   Property  Domain()  As   String
43               Get
44                   Return  _Domain
45               End   Get
46               Set ( ByVal  value  As   String )
47                  _Domain  =  value
48               End   Set
49           End Property
50 
51           Public   Property  Password()  As   String
52               Get
53                   Return  _Password
54               End   Get
55               Set ( ByVal  value  As   String )
56                  _Password  =  value
57               End   Set
58           End Property
59 
60           Public   Property  UserName()  As   String
61               Get
62                   Return  _UserName
63               End   Get
64               Set ( ByVal  value  As   String )
65                  _UserName  =  value
66               End   Set
67           End Property
68 
69           Public   Function  GetFormsCredentials( ByRef  authCookie  As  System.Net.Cookie,  ByRef  userName  As   String ByRef  password  As   String ByRef  authority  As   String As   Boolean   Implements  Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
70           ' ---注意此处必须设置为False,否则论证为失败
71               Return   False
72           End Function
73 
74           Public   ReadOnly   Property  ImpersonationUser()  As  System.Security.Principal.WindowsIdentity  Implements  Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
75               Get
76                   Return   Nothing
77               End   Get
78           End Property
79 
80           Public   ReadOnly   Property  NetworkCredentials()  As  System.Net.ICredentials  Implements  Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
81               Get
82                   Return   New  System.Net.NetworkCredential( Me .UserName,  Me .Password,  Me .Domain)
83               End   Get
84           End Property
85       End Class


你可能感兴趣的:(server)