【发布时间】:2023-03-13 12:26:01
【问题描述】:
我需要在 Reporting Services 中启用 CORS,以便我可以使用 ajax 从我的 Web 应用程序下载报告。 到目前为止我了解到的是,SSRS 不再使用 IIS,而是使用 http.sys 来服务 web.requests。 有没有一种简单的方法可以将 CORS 支持添加到 SSRS (2012)?
【问题讨论】:
标签: reporting-services http.sys
我需要在 Reporting Services 中启用 CORS,以便我可以使用 ajax 从我的 Web 应用程序下载报告。 到目前为止我了解到的是,SSRS 不再使用 IIS,而是使用 http.sys 来服务 web.requests。 有没有一种简单的方法可以将 CORS 支持添加到 SSRS (2012)?
【问题讨论】:
标签: reporting-services http.sys
我设法通过将以下代码添加到报告服务器目录中的 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 干杯 戴夫
【讨论】:
对于 SSRS 2017(Restful API) 使用 SSMS 连接到报告服务器,并确保在连接对话框中将服务类型设置为 Reporting Services。 此外,如果您使用不同的身份验证方法,请设置并输入您的用户名/密码
连接后,在头节点“服务器”上单击鼠标右键-> 属性-> 高级 你会发现所有的CORS属性,设置你需要的
【讨论】:
去年一个类似的问题引起了微软员工"that's not possible, use ReportViewer control"的回答。
【讨论】: