c# - 以编程方式登录到 Crystal Reports Server

标签 c# asp.net 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);

我确实找到了 this question ,这让我走到了一半,但它没有告诉我如何将 token 传递给 InfoView .NET。一些较旧的文档还提到需要 cookie。我还发现其他网站显示如何将它传递给 Java InfoView,但我需要 .NET 版本。

最佳答案

我用了this post作为此解决方案的引用。

这个解决方案有两个部分。

  • 自定义网络应用程序中用于创建 CMS session 的页面
    • 因为我的网络应用知道登录用户。
  • 服务器上用于绕过 InfoView 登录的页面
    • 因为我的网络应用无法为 InfoView 设置 session 变量和 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);
    

复制动态链接库

  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,请参阅上面的注释。)

就是这样。这对我有用。

关于c# - 以编程方式登录到 Crystal Reports Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2031905/

相关文章:

C# + iTunes COM : iTunes event sometimes gets raised, 通常不会

c# - 在WPF中使用MVVM将筛选器文本框添加到组合框

c# - 如何测试返回的数组至少包含一个具有特定属性值的值

c# - jquery $.when 不通过母版页中的等待功能工作

c# - 使用存储库模式 - 出于 EF 性能原因选择实体的特定字段

c# - 您是否缺少 using 指令或程序集引用? C# 错误

asp.net - ORA-1017 无效的用户名/密码

crystal-reports - Crystal Reports 打印空白页

java - 不支持打开 SAP Crystal Reports for Enterprise 报表