public partial classOne : System.Web.UI.Page
{protected void Page_Load(objectsender, EventArgs e)
{if (!IsPostBack)
{
ReportParameter para= new ReportParameter("ReportParameter1", "1");
ReportViewer1.ServerReport.ReportServerCredentials= newMyReportServerCredentials();
ReportViewer1.ServerReport.ReportServerUrl= new Uri("http://报表服务器地址/reportserver");
ReportViewer1.ServerReport.ReportPath= "/报表地址";
ReportViewer1.ServerReport.SetParameters(newReportParameter[] { para });
}
}
}
[Serializable]public sealed classMyReportServerCredentials : IReportServerCredentials
{publicWindowsIdentity ImpersonationUser
{get{//Use the default Windows user. Credentials will be//provided by the NetworkCredentials property.
return null;
}
}publicICredentials 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 newException("Missing user name from web.config file");//Password
string password =ConfigurationManager.AppSettings
["MyReportViewerPassword"];if (string.IsNullOrEmpty(password))throw newException("Missing password from web.config file");//Domain
string domain =ConfigurationManager.AppSettings
["MyReportViewerDomain"];if (string.IsNullOrEmpty(domain))throw newException("Missing domain from web.config file");return newNetworkCredential(userName, password, domain);
}
}public bool GetFormsCredentials(outCookie authCookie,out string userName, out stringpassword,out stringauthority)
{
authCookie= null;
userName= null;
password= null;
authority= null;//Not using form credentials
return false;
}
}