ReportVeiw如何以指定的用戶登錄報表服務器檢閱報表

定義一個自定義連結類:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Principal;
using System.Net;

/// <summary>
/// CustomReportCredentials 的摘要描述
/// </summary>
public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{

    // local variable for network credential.
    private string _UserName;
    private string _PassWord;
    private string _DomainName;
    public CustomReportCredentials(string UserName, string PassWord, string DomainName)
    {
        _UserName = UserName;
        _PassWord = PassWord;
        _DomainName = DomainName;
    }
    public WindowsIdentity ImpersonationUser
    {
        get
        {
            return null;  // not use ImpersonationUser
        }
    }
    public ICredentials NetworkCredentials
    {
        get
        {

            // use NetworkCredentials
            return new NetworkCredential(_UserName, _PassWord, _DomainName);
        }
    }
    public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
    {

        // not use FormsCredentials unless you have implements a custom autentication.
        authCookie = null;
        user = password = authority = null;
        return false;
    }

}

 對ReportView的設定如下:
    this.ReportViewer1.ServerReport.ReportServerCredentials = new CustomReportCredentials(Username, Password, Domain);
                this.ReportViewer1.ServerReport.ReportServerUrl = new Uri(ReportURL);
                this.ReportViewer1.ServerReport.ReportPath = ReportName
                this.ReportViewer1.Visible = true;

同時,在報表服務器中建立對應的用戶信息.
在Reports中"站台設定"的"設定全站台的安全性"中建立對應的使用者信息,並賦予"系統管理員"的權限.

posted @ 2008-05-29 13:08  马建康  阅读(252)  评论(0)    收藏  举报