使用SSRS ASP.NET ReportViewer和Web Service进行Windows身份验证

Llo*_*oyd 5 asp.net reporting-services ssrs-2008

我目前在使用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;
    }
}
Run Code Online (Sandbox Code Playgroud)

}

但是,当此代码执行时,我现在从Web服务和报告服务获得401.

这是怎么回事?他们都在同一个域名上.我想使用当前用户而不是当前机器.如果我在报表服务器上运行报表,它会在正确的用户名下列出,而不是从我的网站上.

mar*_*net 0

代替

return (WindowsIdentity)HttpContext.Current.User.Identity;
Run Code Online (Sandbox Code Playgroud)

你可以尝试

return WindowsIdentity.GetCurrent();
Run Code Online (Sandbox Code Playgroud)