我目前在使用 SSRS 时遇到了一些问题。我有一个使用 Windows 身份验证的 ASP.NET 网站。这很好,我知道网站当前用户是当前登录的用户。
在这个站点上有一个 webforms ReportViewer。当我不设置凭据时,这可以正常工作。但是查看 SQL Server 中报告的执行日志,用户名被列为 DOMAIN\MACHINE。
我尝试将 ReportServerCredentials 属性设置为如下所示的类:
[Serializable]
public class ReportCredentials : IReportServerCredentials   
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
    authCookie = null;
    userName = null;
    password = null;
    authority = null;
    return false;
}
public WindowsIdentity ImpersonationUser
{
    get {
        return (WindowsIdentity)HttpContext.Current.User.Identity;
    }
}
public ICredentials NetworkCredentials
{
    get {
        return null;
    }
}
}
但是,当执行此代码时,我现在从 Web 服务和报告服务返回 401。
这是怎么回事?他们都在同一个域上。我想使用当前用户而不是当前机器。如果我在报告服务器上运行报告,它会在正确的用户名下列出,而不是来自我的网站。