如何在ASP.NET程序中使用报表查看器控件并传递用户凭据

本文介绍了一种自定义凭证的方法,用于Microsoft Reporting Services。通过创建一个名为CustomReportCredentials的类,可以实现特定的安全验证需求。该类实现了IReportServerCredentials接口,并提供了用户名、密码和域名的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步,需要创建一个自定义的Credentails类型

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;
    }

}

第二步,在代码中这样编写

IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

转载于:https://www.cnblogs.com/chenxizhang/archive/2009/05/21/1486308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值