简体   繁体   English

以编程方式登录Crystal Reports Server

[英]Programmatic Logon to Crystal Reports Server

I have a Web Forms app that uses forms authentication. 我有一个使用表单身份验证的Web窗体应用程序。 I have a Crystal Reports Server 2008 V1 server with InfoView .NET installed and working. 我有一个Crystal Reports Server 2008 V1服务器,安装并运行InfoView .NET。 I have some Enterprise accounts setup. 我有一些企业帐户设置。 EDIT: I should mention that my Web Forms app is on a different server from Crystal Reports Server. 编辑:我应该提到我的Web窗体应用程序与Crystal Reports Server位于不同的服务器上。

I need to know how to log on to InfoView .NET programmatically on my custom ASP .NET page (C#) and then transfer the user to InfoView without them having to type in the logon information. 我需要知道如何在我的自定义ASP .NET页面(C#)上以编程方式登录InfoView .NET,然后将用户转移到InfoView,而无需输入登录信息。

Something like this would be nice (C#): 像这样的东西会很好(C#):

string username = "blah";
string password = "asdf";

// create logon token for crystal reports server
// .. // this is the code I need
Response.Redirect(url);

I did find this question , which gets me partway there, but it doesn't tell me how to pass the token to InfoView .NET. 我确实找到了这个问题 ,它让我在那里,但它并没有告诉我如何将令牌传递给InfoView .NET。 Some older docs also mention needing a cookie. 一些较旧的文档也提到需要cookie。 I've also found other sites that show how to pass it to Java InfoView, but I need the .NET version. 我还发现其他网站显示如何将其传递给Java InfoView,但我需要.NET版本。

I used this post as reference for this solution. 我用这篇文章作为这个解决方案的参考。

There are two pieces to this solution. 这个解决方案有两个部分。

  • A page in custom web app to create a CMS session 自定义Web应用程序中用于创建CMS会话的页面
    • Because my web app knows the logged on user. 因为我的网络应用程序知道登录用户。
  • A page on the server to bypass the InfoView login 服务器上用于绕过InfoView登录的页面
    • Because my web app can't set Session vars and Cookies for InfoView. 因为我的网络应用程序无法为InfoView设置会话变量和Cookie。

Here are the steps: 以下是步骤:

  1. Setup the transfer page in your web app. 在您的网络应用中设置转移页面。
  2. Copy a needed DLL onto the server. 将所需的DLL复制到服务器上。
  3. Setup the bypass page on the server. 在服务器上设置旁路页面。

Transfer Page 转移页面

  1. You have to have the Crystal Reports Server SDK installed. 您必须安装Crystal Reports Server SDK。 It can be installed from the Crystal Reports Server CD (it's called client tools or something similar). 它可以从Crystal Reports Server CD安装(它称为客户端工具或类似的东西)。
  2. Add a project reference to CrystalDecisions.Enterprise.Framework. 添加对CrystalDecisions.Enterprise.Framework的项目引用。 Set it to Copy Local = True. 将其设置为Copy Local = True。
  3. Create a page. 创建一个页面。 Add a button to it. 添加一个按钮。 Add an OnClick event to the button. 将OnClick事件添加到按钮。
  4. Page code-behind namespace reference: 页面代码隐藏命名空间参考:

     using CrystalDecisions.Enterprise; 
  5. OnClick event code OnClick事件代码

     string username = "user"; string password = "password"; string server = "CMSNAME:6400"; string auth_type = "secEnterprise"; // logon SessionMgr session_mgr = new SessionMgr(); EnterpriseSession session = session_mgr.Logon(username, password, server, auth_type); // get the serialized session string session_str = session.SerializedSession; // pass the session to our custom bypass page on the CRS string url = "http://reportserver.domain.com/InfoViewApp/transfer.aspx?session=" url += HttpUtility.UrlEncode(session_str); Response.Redirect(url); 

Copy the DLL 复制DLL

  1. Build the project that contains the Transfer page. 构建包含“转移”页面的项目。
  2. In the project folder, under bin/Debug, find the file: CrystalDecisions.Enterprise.Framework.dll and copy it to the server into: C:\\Program Files\\Business Objects\\BusinessObjects Enterprise 12.0\\Web Content\\InfoViewApp\\InfoViewApp\\bin. 在项目文件夹的bin / Debug下,找到文件:CrystalDecisions.Enterprise.Framework.dll并将其复制到服务器:C:\\ Program Files \\ Business Objects \\ BusinessObjects Enterprise 12.0 \\ Web Content \\ InfoViewApp \\ InfoViewApp \\ bin 。 For Windows 2008 R2 , "Program Files" in the path should be "Program Files (x86)" instead. 对于Windows 2008 R2 ,路径中的“Program Files”应改为“Program Files(x86)”。

Bypass Page 绕过页面

  1. Open Notepad on the server and paste the following into it. 在服务器上打开记事本并将以下内容粘贴到其中。

     <%@ Page Language="C#" %> <script runat="server"> private const string SESSION_PARAM = "session"; private const string SESSION_KEY = "INFOVIEW_SESSION"; private const string COOKIE_KEY = "InfoViewdotnetses"; private const string LOGON_URL = "logon.aspx"; protected void Page_Load(object sender, EventArgs e) { try { if (Request.QueryString[SESSION_PARAM] != null) { string sessionStrRaw = Request.QueryString[SESSION_PARAM]; string sessionStr = System.Web.HttpUtility.UrlDecode(sessionStrRaw); CrystalDecisions.Enterprise.SessionMgr sessionMgr = new CrystalDecisions.Enterprise.SessionMgr(); CrystalDecisions.Enterprise.EnterpriseSession entSession = sessionMgr.GetSession(sessionStr); BusinessObjects.Enterprise.Infoview.Common.CrystalIdentity identity; identity = new BusinessObjects.Enterprise.Infoview.Common.CrystalIdentity(entSession, System.Web.HttpContext.Current); HttpContext.Current.Session.Add(SESSION_KEY, identity); //Create the InfoViewdotnetses cookie which holds the SerializedSession HttpCookie InfoViewdotnetses = new HttpCookie(COOKIE_KEY); InfoViewdotnetses.Value = System.Web.HttpUtility.UrlEncode(sessionStrRaw); InfoViewdotnetses.Path = @"/"; Response.Cookies.Add(InfoViewdotnetses); } Response.Redirect(LOGON_URL); } catch (Exception ex) { Response.Write(ex.ToString()); } } </script> 
  2. Save the page as transfer.aspx into: C:\\Program Files\\Business Objects\\BusinessObjects Enterprise 12.0\\Web Content\\InfoViewApp\\InfoViewApp. 将页面保存为transfer.aspx到:C:\\ Program Files \\ Business Objects \\ BusinessObjects Enterprise 12.0 \\ Web Content \\ InfoViewApp \\ InfoViewApp。 (For Windows 2008 R2, see note above.) (对于Windows 2008 R2,请参阅上面的注释。)

That's it. 而已。 That's what worked for me. 这对我有用。

This will resolve your problem: 这将解决您的问题:

Copy the code to page_load of the aspx to pass the authenticated token to the report. 将代码复制到aspx的page_load,以将经过身份验证的令牌传递给报告。

    protected void Page_Load(object sender, EventArgs e)
    {
        string username = "user";
        string password = "password";
        string server = "<boe server>";
        string auth_type = "<auth type>";
        // e.g. string auth_type = "Windows AD"

        string token; string tokenEncoded; 

        int reportid = <reportid>; 
        string report_params = "<param1>=<value1>&<param2>=<value2>";

        // logon
        SessionMgr session_mgr = new SessionMgr();
        EnterpriseSession session = session_mgr.Logon(username, password, server, auth_type);

        // create token from session manager
        token = session.LogonTokenMgr.CreateLogonTokenEx("", 120, 100);
        tokenEncoded = HttpUtility.UrlEncode(token);

        // pass the token to the custom bypass page on the CRS
        string url = string.Format("http://{0}/OpenDocument/opendoc/openDocument.aspx?sIDType=wid&iDocID={1}&lsS{2}&token={3}",
            server, reportid, param, tokenEncoded);

        Response.Redirect(url);
    }

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

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