3

我需要在 Reporting Services 中启用 CORS,以便我可以使用 ajax 从我的 Web 应用程序下载报告。到目前为止,我了解到的是,SSRS 不再使用 IIS,而是使用 http.sys 来服务 web.requests。有没有一种简单的方法可以将 CORS 支持添加到 SSRS(2012)?

4

4 回答 4

4

我设法通过将以下代码添加到 reportserver 目录中的 global.asax 来完成这项工作。

<%@ Application Inherits="Microsoft.ReportingServices.WebServer.Global"  %>
<%@ Import namespace="System.Web" %>
<%@ Import namespace="System.Security" %>

<script runat="server">
private static bool init;
private static object lockObject = new object();

void Application_BeginRequest(object sender, EventArgs e)
{
    lock(lockObject)
    {
        if (!init)
        {
            HttpContext context = HttpContext.Current;
            HttpResponse response = context.Response;
            string allow = @"Access-Control-Allow-Origin";

            // enable CORS
            response.AddHeader(allow, "http://yoursourcedomain.com");
            response.AddHeader(@"X-Frame-Options", "ALLOW-FROM http://yoursourcedomain.com");
            response.AddHeader(@"Access-Control-Allow-Credentials", "true");

            if (context.Request.HttpMethod == "OPTIONS")
            {
                response.AddHeader(@"Access-Control-Allow-Methods", "GET, POST");
                response.AddHeader(@"Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
                response.AddHeader(@"Access-Control-Max-Age", "1728000");
                response.StatusCode = 200;
                response.End();
                HttpApplication httpApplication = (HttpApplication)sender;
                httpApplication.CompleteRequest();
            }
            init = true;
        }
        else
        {
            init = false;
        }
    }
}
</script>

HTH 为戴夫欢呼

于 2016-08-02T04:57:45.127 回答
2

对于 SSRS 2017(Restful API)使用 SSMS 连接到报告服务器,并确保在连接对话框中将服务类型设置为 Reporting Services。此外,如果您使用不同的身份验证方法,请设置并输入您的用户名/密码

连接后,在头节点“服务器”上右键单击 -> 属性 -> 高级 你会找到所有 CORS 属性,设置你需要的

https://docs.microsoft.com/en-us/sql/reporting-services/tools/server-properties-advanced-page-reporting-services?view=sql-server-2017

于 2019-01-08T04:53:11.950 回答
0

回复:et3rnal 的正确答案(有很多方法,但这可能是最直接的,推荐):

在此处输入图像描述

如前所述,您可以在此处控制请求标头和 CORS 设置。

于 2020-05-26T21:40:47.590 回答
0

去年一个类似的问题引起了微软员工的“那不可能,使用 ReportViewer 控件”的回答。

于 2015-09-01T08:34:48.477 回答