加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 21:59:33 所属栏目:百科 来源:网络整理
导读:我似乎无法使用HttpClient发送报告服务器的请求,因为结果总是如此 401(未经授权). 行动是 public async TaskFileStreamResult SSRSTest() { //set credentials using (var handler = new HttpClientHandler { Credentials = new NetworkCredential("userName
我似乎无法使用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");
                }
            }

额外:

Pass a Report Parameter Within a URL

Export a Report Using URL Access

Export Formats

Generate Data Feeds from a Report

解决方法

我使用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的其余代码是相同的.

额外:

Authentication with the Report Server

Selecting a Credential Type

Understanding SQL Server Reporting Services Authentication

Configure Basic Authentication on the Report Server

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读