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.
I used this post as reference for this solution.
There are two pieces to this solution.
Here are the steps:
Page code-behind namespace reference:
using CrystalDecisions.Enterprise;
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);
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>
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.