Интерфейс IReportServerConnection2
Содержит сведения о соединении с сервером отчетов, если элемент управления веб-форм ReportViewer используется без состояния сеанса.
Пространство имен: Microsoft.Reporting.WebForms
Сборка: Microsoft.ReportViewer.WebForms (в microsoft.reportviewer.webforms.dll)
Синтаксис
'Декларация
'Применение
Замечания
Если реализация интерфейса IReportServerConnection2 указана в настройках файла Web.config, значения свойств ReportServerUrl, Timeout, Cookies и Headers не будут использоваться на экземпляре ServerReport. Вместо них будут использоваться значения, содержащиеся в реализации IReportServerConnection2. В дополнение к этим свойствам будут также использоваться сведения об учетных данных, содержащиеся в реализации IReportServerConnection2.
Дополнительные сведения о задании соединений с помощью элемента управления ReportViewer см. в разделе Задание соединений и учетных данных для серверного веб-элемента управления ReportViewer.
Дополнительные сведения о настройке файла Web.config для ReportViewerServerConnection см. в разделе Параметры файла web.config для ReportViewer.
Примеры
Следующий пример содержит реализацию интерфейса IReportServerConnection2, который получает сведения об учетных данных и URL-адресе сервера отчетов из файла Web.config.
Перед использованием примера необходимо добавить пять пар «ключ-значение» в файл приложения Web.config в блоке appSettings: ReportViewerServerConnection, MyReportViewerUser, MyReportViewerPassword, MyReportViewerDomain и MyReportServerUrl, где значения соответствуют имени пользователя, паролю и домену для соединения с сервером отчетов и URL-адресу сервера отчетов. Значению ReportViewerServerConnection необходимо присвоить полное имя сборки для реализации класса IReportServerConnection2.
Дополнительные сведения о настройке файла Web.config для ReportViewerServerConnection см. в разделе Параметры файла web.config для ReportViewer.
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
Понятия
Параметры файла web.config для ReportViewer
Задание соединений и учетных данных для серверного веб-элемента управления ReportViewer