簡體   English   中英

以編程方式登錄Crystal Reports Server

[英]Programmatic Logon to Crystal Reports Server

我有一個使用表單身份驗證的Web窗體應用程序。 我有一個Crystal Reports Server 2008 V1服務器,安裝並運行InfoView .NET。 我有一些企業帳戶設置。 編輯:我應該提到我的Web窗體應用程序與Crystal Reports Server位於不同的服務器上。

我需要知道如何在我的自定義ASP .NET頁面(C#)上以編程方式登錄InfoView .NET,然后將用戶轉移到InfoView,而無需輸入登錄信息。

像這樣的東西會很好(C#):

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

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

我確實找到了這個問題 ,它讓我在那里,但它並沒有告訴我如何將令牌傳遞給InfoView .NET。 一些較舊的文檔也提到需要cookie。 我還發現其他網站顯示如何將其傳遞給Java InfoView,但我需要.NET版本。

我用這篇文章作為這個解決方案的參考。

這個解決方案有兩個部分。

  • 自定義Web應用程序中用於創建CMS會話的頁面
    • 因為我的網絡應用程序知道登錄用戶。
  • 服務器上用於繞過InfoView登錄的頁面
    • 因為我的網絡應用程序無法為InfoView設置會話變量和Cookie。

以下是步驟:

  1. 在您的網絡應用中設置轉移頁面。
  2. 將所需的DLL復制到服務器上。
  3. 在服務器上設置旁路頁面。

轉移頁面

  1. 您必須安裝Crystal Reports Server SDK。 它可以從Crystal Reports Server CD安裝(它稱為客戶端工具或類似的東西)。
  2. 添加對CrystalDecisions.Enterprise.Framework的項目引用。 將其設置為Copy Local = True。
  3. 創建一個頁面。 添加一個按鈕。 將OnClick事件添加到按鈕。
  4. 頁面代碼隱藏命名空間參考:

     using CrystalDecisions.Enterprise; 
  5. 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); 

復制DLL

  1. 構建包含“轉移”頁面的項目。
  2. 在項目文件夾的bin / Debug下,找到文件:CrystalDecisions.Enterprise.Framework.dll並將其復制到服務器:C:\\ Program Files \\ Business Objects \\ BusinessObjects Enterprise 12.0 \\ Web Content \\ InfoViewApp \\ InfoViewApp \\ bin 。 對於Windows 2008 R2 ,路徑中的“Program Files”應改為“Program Files(x86)”。

繞過頁面

  1. 在服務器上打開記事本並將以下內容粘貼到其中。

     <%@ 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. 將頁面保存為transfer.aspx到:C:\\ Program Files \\ Business Objects \\ BusinessObjects Enterprise 12.0 \\ Web Content \\ InfoViewApp \\ InfoViewApp。 (對於Windows 2008 R2,請參閱上面的注釋。)

而已。 這對我有用。

這將解決您的問題:

將代碼復制到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