views:

913

answers:

1

I have a Web Forms app that uses forms authentication. I have a Crystal Reports Server 2008 V1 server with InfoView .NET installed and working. I have some Enterprise accounts setup. EDIT: I should mention that my Web Forms app is on a different server from 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.

Something like this would be nice (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. Some older docs also mention needing a cookie. I've also found other sites that show how to pass it to Java InfoView, but I need the .NET version.

+2  A: 

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
    • Because my web app knows the logged on user.
  • A page on the server to bypass the InfoView login
    • Because my web app can't set Session vars and Cookies for InfoView.

Here are the steps:

  1. Setup the transfer page in your web app.
  2. Copy a needed DLL onto the server.
  3. Setup the bypass page on the server.

Transfer Page

  1. You have to have the Crystal Reports Server SDK installed. It can be installed from the Crystal Reports Server CD (it's called client tools or something similar).
  2. Add a project reference to CrystalDecisions.Enterprise.Framework. Set it to Copy Local = True.
  3. Create a page. Add a button to it. Add an OnClick event to the button.
  4. Page code-behind namespace reference:

    using CrystalDecisions.Enterprise;
    
  5. OnClick event code

    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

  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. For Windows 2008 R2, "Program Files" in the path should be "Program Files (x86)" instead.

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. (For Windows 2008 R2, see note above.)

That's it. That's what worked for me.

Kasey Speakman