IReportServerConnection2 インターフェイス
Provides report server connection information when the ReportViewer Web forms control is used with no session state.
名前空間: Microsoft.Reporting.WebForms
アセンブリ: Microsoft.ReportViewer.WebForms (microsoft.reportviewer.webforms.dll 内)
構文
'宣言
'使用
解説
When an implementation of the IReportServerConnection2 interface is specified in the Web.config settings, the values for the ReportServerUrl, Timeout, Cookies and Headers properties on the ServerReport instance will not be used. The values provided by the IReportServerConnection2 implementation will be used instead. In addition to these properties, the credential information that is provided by the IReportServerConnection2 implementation will also be used.
For more information about how to specify connections with the ReportViewer control, see ReportViewer Web サーバー コントロールの接続と資格情報の指定.
For more information about the ReportViewerServerConnection Web.config setting, see ReportViewer 用の Web.config 設定.
例
The following example provides an implementation of IReportServerConnection2 interface that retrieves the report server URL and credential information from the Web.config file.
Before using the example, five key/value pairs must be added to the application's Web.config file in the appSettings block: ReportViewerServerConnection, MyReportViewerUser, MyReportViewerPassword, MyReportViewerDomain, and MyReportServerUrl, where the values correspond to the user name, password, and domain for connecting to the report server, and the URL of the report server. The ReportViewerServerConnection value must be set to the fully qualified assembly name for the implementation of the IReportServerConnection2 class.
For more information about the Web.config ReportViewerServerConnection setting, see ReportViewer 用の Web.config 設定.
public sealed class MyReportServerConnection : IReportServerConnection2
{
public WindowsIdentity ImpersonationUser
{
get
{
// Use the default Windows user. Credentials will be
// provided by the NetworkCredentials property.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Read the user information from the web.config file.
// By reading the information on demand instead of
// storing it, the credentials will not be stored in
// session, reducing the vulnerable surface area to the
// web.config file, which can be secured with an ACL.
// User name
string userName =
ConfigurationManager.AppSettings
["MyReportViewerUser"];
if (string.IsNullOrEmpty(userName))
throw new Exception(
"Missing user name from Web.config file");
// Password
string password =
ConfigurationManager.AppSettings
["MyReportViewerPassword"];
if (string.IsNullOrEmpty(password))
throw new Exception(
"Missing password from Web.config file");
// Domain
string domain =
ConfigurationManager.AppSettings
["MyReportViewerDomain"];
if (string.IsNullOrEmpty(domain))
throw new Exception(
"Missing domain from Web.config file");
return new NetworkCredential(userName, password, domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string userName, out string password,
out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;
// Not using form credentials
return false;
}
public Uri ReportServerUrl
{
get
{
string url =
ConfigurationManager.AppSettings[
"MyReportServerUrl"];
if (string.IsNullOrEmpty(url))
throw new Exception(
"Missing url from the Web.config file");
return new Uri(url);
}
}
public int Timeout
{
get
{
return 60000; // 60 seconds
}
}
public IEnumerable<Cookie> Cookies
{
get
{
// No custom cookies
return null;
}
}
public IEnumerable<string> Headers
{
get
{
// No custom headers
return null;
}
}
}
Public NotInheritable Class MyReportServerConnection
Implements IReportServerConnection2
Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
Implements IReportServerConnection2.ImpersonationUser
Get
'Use the default Windows user. Credentials will be
'provided by the NetworkCredentials property.
Return Nothing
End Get
End Property
Public ReadOnly Property NetworkCredentials() As ICredentials _
Implements IReportServerConnection2.NetworkCredentials
Get
'Read the user information from the web.config file.
'By reading the information on demand instead of storing
'it, the credentials will not be stored in session,
'reducing the vulnerable surface area to the web.config
'file, which can be secured with an ACL.
'User name
Dim userName As String = _
ConfigurationManager.AppSettings("MyReportViewerUser")
If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config file")
End If
'Password
Dim password As String = _
ConfigurationManager.AppSettings("MyReportViewerPassword")
If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config file")
End If
'Domain
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 NetworkCredential(userName, password, domain)
End Get
End Property
Public Function GetFormsCredentials(ByRef authCookie As Cookie, _
ByRef userName As String, _
ByRef password As String, _
ByRef authority As String) _
As Boolean _
Implements IReportServerConnection2.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
'Not using form credentials
Return False
End Function
Public ReadOnly Property ReportServerUrl() As Uri
Implements IReportServerConnection2.ReportServerUrl
Get
Dim url As String = ConfigurationManager.AppSettings("MyReportViewerUrl")
If (String.IsNullOrEmpty(url)) Then
Throw New Exception("Missing url from the web.config file")
End If
Return New Uri(url)
End Get
End Property
Public ReadOnly Property Timeout() As Integer Implements IReportServerConnection2.Timeout
Get
Return 60000 '60 seconds
End Get
End Property
Public ReadOnly Property Cookies() As IEnumerable(Of Cookie) Implements IReportServerConnection2.Cookies
Get
Return Nothing
End Get
End Property
Public ReadOnly Property Headers() As IEnumerable(Of String) Implements IReportServerConnection2.Headers
Get
Return Nothing
End Get
End Property
End Class
参照
リファレンス
IReportServerConnection2 メンバ
Microsoft.Reporting.WebForms 名前空間
IReportServerCredentials
概念
ReportViewer 用の Web.config 設定
ReportViewer Web サーバー コントロールの接続と資格情報の指定