C#学习教程:将凭据传递给SqlReportServer2008我尝试使用ReportService控件构建一个ASP.NET网站。您可能已经知道,SSRS2008不允许匿名登录。所以我试图将凭据传递给SSRS,SSRS将存储在我的网页中,以便用户无需登录即可查看报告。我找到了下面的代码并将其放入我的WebForm中,但我遇到了报告参数问题。关于如何避免刷新整个页面或其他将登录信息传递给SSRS的方法有什么建议吗?非常感谢。使用系统;使用系统配置;使用系统数据;使用System.Linq;使用System.Web;使用System.Web.Security;使用System.Web.UI;使用System.Web.UI.HtmlControls;使用System.Web.UI.WebControls;使用System.Web.UI.WebControls.WebParts;使用System.Xml.Linq;使用System.Net;使用Microsoft.Reporting.WebForms;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){ReportViewer1.Width=800;ReportViewer1.Height=600;ReportViewer1.ProcessingMode=ProcessingMode.Remote;IReportServerCredentialsirsc=newCustomReportCredentials("administrator","MYpassworw","domena");ReportViewer1.ServerReport.ReportServerCredentials=irsc;ReportViewer1.ServerReport.ReportServerUrl=newUri("http://192.168.0.1/ReportServer/");ReportViewer1.ServerReport.ReportPath="/autonarudzba/listanarudzbi";ReportViewer1.ServerReport.Refresh();}}公共类CustomReportCredentials:IReportServerCredentials{私有字符串_UserName;私有字符串_PassWord;私有字符串_DomainName;publicCustomReportCredentials(stringUserName,stringPassWord,stringDomainName){_UserName=UserName;_密码=密码;_DomainName=域名;得到{返回null;}}publicICredentialsNetworkCredentials{get{returnnewNetworkCredential(_UserName,_PassWord,_DomainName);}}publicboolGetFormsCredentials(outCookieauthCookie,outstringuser,outstringpassword,outstringauthority){authCookie=null;用户=密码=权限=空;返回假;我并没有真正搞乱SSRS-但我的ASP.NET帽子告诉我你可能想将这些东西包装在if(!IsPostBack)块中以防止它在页面刷新时运行我的猜测是ReportViewer1.ServerReport。Refresh()再次提取默认值。protectedvoidPage_Load(objectsender,EventArgse){if(!this.IsPostBack){ReportViewer1.Width=800;ReportViewer1.Height=600;ReportViewer1.ProcessingMode=ProcessingMode.Remote;IReportServerCredentialsirsc=newCustomReportCredentials("administrator"MYpassworw","domena");ReportViewer1.ServerReport.ReportServerCredentials=irsc;ReportViewer1.ServerReport.ReportServerUrl=newUri("http://192.168.0.1/ReportServer/");ReportViewer1.ServerReport.ReportPath="/autonarudzba/listanarudzbi";ReportViewer1.ServerReport.Refresh();}}我创建了一个新函数并在reportViewer的属性、事件、设计视图中选择了它。(在选择INITi之后)页面工作正常并且我可以更改参数的值。Default.aspx现在看起来像:Default.aspx.cs看起来像这样publicvoidAdmir(objectsender,EventArgse){ReportViewer1.Width=800;ReportViewer1.Height=600;ReportViewer1.ProcessingMode=ProcessingMode.Remote;IReportServerCredentialsirsc=newCustomReportCredentials("administrator","mypass","domena");ReportViewer1.ServerReport.ReportServerCredentials=irsc;ReportViewer1.ServerReport.ReportServerUrl=newUri("http://192.168.0.1/ReportServer/");报表查看器1。ServerReport.ReportPath="/autonarudzba/listanarudzbi";ReportViewer1.ServerReport.Refresh();}protectedvoidPage_Load(objectsender,EventArgse){}您可以在页面加载事件中使用以下代码提供参数ReportParameter[]reportParameterCollection=newReportParameter[1];//数组大小描述了参数的个数。reportParameterCollection[0]=newReportParameter();reportParameterCollection[0].Name="ACCMGR";//给你的参数名称reportParameterCollection[0].Values。添加(“12”);//传递参数s的值在这里。ReportViewer1.ServerReport.SetParameters(reportParameterCollection);ReportViewer1.ServerReport.Refresh();我希望这对你有用我找到了解决方案你必须先设置凭据,然后你必须为报告查看器设置参数。以上就是C#学习教程:向SqlReportServer2008传递凭证的全部内容,如果对您有用,需要了解更多C#学习教程,希望您多多关注——rvCommon。ProcessingMode=ProcessingMode.Remote;rv常见的。ServerReport.ReportServerUrl=newSystem.Uri("SSRSReportServerURL");rvCommon.ServerReport.ReportPath="/ReportParts/CustomerMainReport2";Microsoft.Reporting.WebForms.ReportParameter[]RptParameters=newMicrosoft.Reporting.WebForms.ReportParameter[1];rvCommon.ServerReport.ReportServerCredentials=newReportCredentials("用户名","密码","");RptParameters[0]=newMicrosoft.Reporting.WebForms.ReportParameter("CustomerId","1");rvCommon.ServerReport.SetParameters(RptParameters);rvCommon.ServerReport.Refresh();本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
