繁体   English   中英

在ASP.NET MVC Action中使用HttpClient来调用SSRS

[英]Using HttpClient inside ASP.NET MVC Action to call SSRS

我似乎无法使用HttpClient发送报告服务器的请求,因为结果总是401(未经授权)

行动是

public async Task<FileStreamResult> SSRSTest()
            {

                //set credentials
                using (var handler = new HttpClientHandler { 
                    Credentials = new NetworkCredential("userName", "password"),
                    UseDefaultCredentials = false
                })

                using (var httpClient = new HttpClient(handler))
                {
                    //get *.pdf from report server
                    var response = await httpClient                      .GetStreamAsync("http://someip/ReportServer/Pages/ReportViewer.aspx?TheRemainingPartOfURL");


                    var contentDisposition = new ContentDisposition
                    {
                        FileName = "SomeReport.pdf",
                        Inline = false
                    };

                    //set content disposition
                    Response.AppendHeader("Content-Disposition", contentDisposition.ToString());

                    //return the file
                    return File(response, "application/pdf");
                }
            }

额外:

在URL中传递报表参数

使用URL访问导出报告

出口格式

从报告生成数据馈送

我使用Fiddler来查看使用浏览器登录时发生了什么

在此输入图像描述

Auth选项卡是

WWW-Authenticate Header is present: Negotiate    
WWW-Authenticate Header is present: NTLM

所以,即使我被告知身份验证是基本的,我需要使用以下内容

 CredentialCache credentialCache = new CredentialCache();
            credentialCache.Add(new Uri("http://youruri"),"NTLM",new NetworkCredential(username, password));

            using (var handler = new HttpClientHandler
            {
                Credentials = credentialCache
            })

HttpClient的其余代码是相同的。

额外:

使用Report Server进行身份验证

选择凭证类型

了解SQL Server Reporting Services身份验证

在报表服务器上配置基本身份验证

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM