【发布时间】:2019-07-23 06:21:25
【问题描述】:
我目前正在尝试使用表单身份验证在我的 Web 应用程序中呈现 SSRS 报告。
我的 SSRS 报告版本是 2016 年。
最初我的印象是 NetworkCredentials 可以工作,在遇到错误后,我发现我们需要使用 FormsAuthentication,并传递 cookie 作为对用户进行身份验证的一种手段。
我已按照以下链接中的指南对报告服务器中的配置文件进行了必要的设置:-
https://github.com/Microsoft/Reporting-Services/tree/master/CustomSecuritySample2016
报告服务在 localhost/ReportServer 和 SSRS 门户,本地主机/报告。我也可以访问所述服务器 远程。
以下是我用来获取经过身份验证的 cookie 的代码。
MyReportingService rsClient = new MyReportingService();
rsClient.Url = "http://xxx.xxx.xxx.xxx/reportserver/ReportService2010.asmx";
try
{
rsClient.LogonUser("user", "password", "");
Cookie myAuthCookie = rsClient.AuthCookie;
HttpCookie cookie = new HttpCookie(myAuthCookie.Name, myAuthCookie.Value);
Response.Cookies.Add(cookie);
}
据推测,这将用于对用户进行身份验证。
Cookie authCookie = new Cookie(cookie2.Name, cookie2.Value);
authCookie.Domain = "DomainName";
rvSiteMapping.ServerReport.ReportServerCredentials = new MyReportServerCredentials(authCookie);
rvSiteMapping.ServerReport.Cookies.Add(authCookie);
在我的表单中,IReportsServerCredentials 类中的身份验证:-
public bool GetFormsCredentials(out Cookie authCookie,
out string user, out string password, out string authority)
{
authCookie = m_authCookie;
user = password = authority = null;
return true; // Use forms credentials to authenticate.
}
我遇到的问题是应用程序将凭据传递给报表服务器时。我相信我一定是做错了这部分,因为虽然我的应用程序确实获得了 cookie,但当它验证 cookie 提供的凭据时,我收到 text/html 错误:-
Object moved to <a href="/ReportServer/logon.aspx?ReturnUrl=%2fReportserver%2fReportExecution2005.asmx" />
此错误是为了响应在以下情况下设置默认的通用身份 HttpContext.Current.User = null。
if (HttpContext.Current != null
&& HttpContext.Current.User != null)
{
userIdentity = HttpContext.Current.User.Identity;
}
else
{
userIdentity = new GenericIdentity("AnonymousUser");
}
我已经尝试在谷歌上搜索答案,但大多数结果都是针对 windows 身份验证以及与表单身份验证相关的少数几个 与我提到的代码非常相似。
【问题讨论】:
标签: c# reporting-services forms-authentication reporting-services-2016