我正在尝试使用ASP.NET Web应用程序连接到Report
(rdlc文件)。我正在使用VS2010而Report Server
是版本2008。
我在报告中有以下网址可以正常使用:
http://server url/Products/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=/Products/Dashboards/Product_tool.rdl&Source=Server Url/Products/Dashboards/Forms/AllItems.aspx&DefaultItemOpen=1
当我在浏览器中输入该URL时,它首先要求输入用户名密码。当我登录时,Report
显示就好了。
现在我需要在Report Viewer
中显示此报告。所以我在Report Viewer
页面添加了aspx
控件。我为它配置了URls:
Report Server:** http://server url/Products/_layouts/ReportServer
Report Path:** /Products/Dashboards/Product_tool.rdl
我不确定这是否正确..?
无论如何,在我的PageLoad
我有以下代码行:
eportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("myuser", "mypass");
ReposrtCredentials
课程取自:http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c65abca7-0fdb-40fb-aabe-718f63377a55/(来自Phil)
现在,当我运行我的Web应用程序时,我收到以下错误:
尝试连接到报表服务器失败。检查你的 连接信息以及报表服务器是兼容的 版本
现在我不确定我提供给Report Viewer
的网址是否正确?或者其他问题可能是什么。
任何人有任何想法......?
答案 0 :(得分:4)
要将SSRS报告集成到ASP.NET应用程序中,请按照下列步骤操作。
首先,实现IReportServerConnection2接口。我做了这样的事情:
public sealed class CustomReportServerConnection : 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[Utility.Constants.AppConst.REPORT_USER].ToString();
if (string.IsNullOrEmpty(userName))
throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_USER_NAME);
// Password
string password = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_PASSWORD].ToString();
if (string.IsNullOrEmpty(password))
throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_PWD);
// Domain
string domain = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORTS_DOMAIN].ToString();
if (string.IsNullOrEmpty(domain))
throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_DOMAIN);
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[Utility.Constants.AppConst.REPORT_SERVER_URL].ToString();
if (string.IsNullOrEmpty(url))
throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_URL);
return new Uri(url);
}
}
public int Timeout
{
get
{
return int.Parse(ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_SERVER_TIME_OUT].ToString());
// return 60000; // 60 seconds
}
}
public IEnumerable<Cookie> Cookies
{
get
{
// No custom cookies
return null;
}
}
public IEnumerable<string> Headers
{
get
{
// No custom headers
return null;
}
}
}
现在,在您的Configuration AppSettings中放置以下键(或从您想要的任何地方提供这些值):
<add key="ReportServerUrl" value="http://sqlServerURL/ReportServer_SQL2008R2"/>
<!--Development TargetReportFolder-->
<add key="TargetReportFolder" value="/AppReporting/"/>
<add key="ReportServerTimeOut" value="600000"/>
<add key="ReportViewerServerConnection" value="FullyQualified Name of ur CustomReportServerConnection,ProjectName"/>
<add key="ReportsUser" value="ReportUser"/>
<add key="ReportsPassword" value="reportPassword"/>
<add key="ReportsDomain" value="myDomain"/>
现在,在你的.aspx页面中,拖动一个reportViewer,如下所示:
<rsweb:ReportViewer ID="RptViewer" runat="server" AsyncRendering="False" SizeToReportContent="true"
ProcessingMode="Remote" Width="100%" BackColor="#F7F8F9" OnReportError="RptViewer_ReportError"
OnReportRefresh="RptViewer_ReportRefresh1" Height="">
</rsweb:ReportViewer>
并在codeBehind中配置ReportViewer ..
正确放置ReportParameter
。
它会给你一个想法...
重点是,您需要正确进行身份验证,因此编写自定义ReportServerConnection
答案 1 :(得分:1)
配置报告查看器时,请检查您使用的帐户是否有权查看报告,因为在使用服务器报告时您必须具有访问权限。 看看这个链接。他们会有所帮助:http://forums.asp.net/t/1562624.aspx/1