1

我正在尝试以pdfin执行报告asp.net c#。我的一切工作都很好,除了sqlauth cookie. 如果我使用iframe并呈现一个虚拟报告,然后sqlAuthCookie在代码隐藏中使用该 cookie(由报告服务器设置),它可以工作,所以我知道我的语法和方法等是正确的。我需要做的是添加sqlauth cookie到 ReportExecution Service cookie Container,或其他传递凭据的方法。我正在使用Forms Authentication. 我正在使用ashx带有调用的处理程序jquery ajax来执行报告。这是我的页面背后的代码。

  public void ProcessRequest(HttpContext context)
    {
        // 8863443a-06d6-4aeb-8fa8-43be545da1a3
        var rs = new ReportExecutionService();
        rs.Credentials = CredentialCache.DefaultCredentials;
        //rs.Credentials = new NetworkCredential("zachariah.curtis", "password", "AGLO");
        rs.Url = ConfigurationManager.AppSettings["ReportExecutionURL"];

        NetworkCredential creds = rs.Credentials.GetCredential(context.Request.Url, context.User.Identity.AuthenticationType);
        rs.LogonUser(creds.UserName, creds.Password, null);

        var cookies = context.Request.Cookies.AllKeys.ToList();
        var cookies3 = rs.CookieContainer.GetCookies(new Uri(rs.Url)); 
        var sqlauth = context.Request.Cookies["sqlAuthCookie"];
        rs.CookieContainer = new CookieContainer();
        cookies.ForEach(delegate(String item)
        {
            rs.CookieContainer.Add(new Cookie(context.Request.Cookies[item].Name, context.Request.Cookies[item].Value, context.Request.Cookies[item].Path, context.Request.Cookies[item].Domain ?? ".usda.gov"));
            rs.CookieContainer.Add(new Cookie("sqlAuthCookie", "A78B8A2D714BF058DF7258927717A4D34FA9F8A0BA54FCCB006543DEBF755D2670636E172675107A9FCAF77F66A0E7E2EE4321464602C7E61138C224B8612B05E12DC1DFF878E8748CE267FF19839198", "/", "iasdev.dev.sc.egov.usda.gov"));
        });


        // Render arguments
        byte[] result = null;
        // Make sure you use your correct org database name of the following line
        string reportPath = "/ProTractsCMT/TestReport";
        var contractId = context.Request["ContractId"];
        string format = "PDF";
        string historyID = null;
        string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

        // Prepare report parameter.

        ParameterValue[] parameters = new ParameterValue[1];
        parameters[0] = new ParameterValue();
        parameters[0].Name = "@CONTRACTID";
        parameters[0].Value = contractId;

        DataSourceCredentials[] credentials = null;
        string showHideToggle = null;
        string encoding;
        string mimeType;
        string extension;
        Warning[] warnings = null;
        ParameterValue[] reportHistoryParameters = null;
        string[] streamIDs = null;

        ExecutionInfo execInfo = new ExecutionInfo();
        ExecutionHeader execHeader = new ExecutionHeader();

        rs.ExecutionHeaderValue = execHeader;

        execInfo = rs.LoadReport(reportPath, historyID);

        //rs.SetExecutionParameters(parameters, "en-us");
        string SessionId = rs.ExecutionHeaderValue.ExecutionID;


        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);

        try
        {
            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
            execInfo = rs.GetExecutionInfo();
            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
        }

        catch (SoapException err)
        {
            Console.WriteLine(err.Detail.OuterXml);
        }
        context.Response.ContentType = "text/plain";
        // save rendered pdf to db
        if (new calculations().SaveReport(result))
        {
            context.Response.Write("true");

        }
        else
        {
            context.Response.Write("true");

        }
    }

你可以看到它在哪里rs.CookieContainer.Add(new Cookie("sqlAuthCookie",这就是我可以让它工作的方式。求求求救!!!谢谢大家!

4

1 回答 1

0

您的设计是否要求您将当前登录用户的凭据/身份验证数据传递给 SSRS?那么,是否允许该用户直接使用该特定凭据执行报告?

通常,我宁愿假设您以您显然已经尝试过的方式使用一些预定义的用户访问和执行您的 RS 执行引擎:

 //rs.Credentials = new NetworkCredential("zachariah.curtis", "password", "AGLO");

您可以在应用设置中配置这些凭据。

于 2011-03-18T23:36:17.610 回答