Accesso programmatico a Crystal Reports Server
-
19-09-2019 - |
Domanda
Ho un'app di moduli Web che utilizza l'autenticazione dei moduli. Ho un server V1 Server Crystal Reports 2008 con InfoView .NET installato e funzionante. Ho alcuni account aziendali configurati. Modifica: dovrei menzionare che la mia app Web Forms è su un server diverso dal server Crystal Reports.
Devo sapere come accedere a InfoView .NET programmaticamente sulla mia pagina ASP .NET personalizzata (C#) e quindi trasferire l'utente su Infoview senza che debbano digitare le informazioni di accesso.
Qualcosa di simile sarebbe bello (C#):
string username = "blah";
string password = "asdf";
// create logon token for crystal reports server
// .. // this is the code I need
Response.Redirect(url);
Ho trovato questa domanda, che mi porta a parte lì, ma non mi dice come passare il token a Infoview .NET. Alcuni documenti più vecchi menzionano anche che necessitano di un biscotto. Ho anche trovato altri siti che mostrano come passarlo a Java Infoview, ma ho bisogno della versione .NET.
Soluzione
ero solito questo post come riferimento per questa soluzione.
Ci sono due pezzi in questa soluzione.
- Una pagina nell'app Web personalizzata per creare una sessione CMS
- Perché la mia app web conosce l'utente registrato.
- Una pagina sul server per bypassare l'accesso all'infocie
- Perché la mia app Web non è in grado di impostare VAR e cookie di sessione per Infoview.
Ecco i passaggi:
- Imposta la pagina di trasferimento nella tua app web.
- Copia una DLL necessaria sul server.
- Imposta la pagina di bypass sul server.
Pagina di trasferimento
- È necessario installare il server Crystal Reports. Può essere installato dal CD Crystal Reports Server (si chiama strumenti client o qualcosa di simile).
- Aggiungi un riferimento di progetto a Crystaldecisions.enterprise.framework. Impostalo per copiare local = true.
- Crea una pagina. Aggiungi un pulsante ad esso. Aggiungi un evento OnClick al pulsante.
Pagina Codice-BEHIND Names Space Reference:
using CrystalDecisions.Enterprise;
Codice evento 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);
Copia la DLL
- Costruisci il progetto che contiene la pagina di trasferimento.
- Nella cartella del progetto, sotto il bin/debug, trova il file: cristaldecisions.enterprise.framework.dll e copialo sul server in: C: Programmi Business Objects BusinessObjects Enterprise 12.0 Web Content InfoViewApp InfoviewApp bin bin . Per Windows 2008 R2, "Programmi" nel percorso dovrebbero essere "Programmi (x86)" invece.
Pagina di bypass
Apri il blocco note sul server e incolla quanto segue.
<%@ 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>
Salva la pagina come Transfer.aspx in: C: Programmi Business Objects BusinessObjects Enterprise 12.0 Web Content InfoViewApp InfoViewApp. (Per Windows 2008 R2, vedi nota sopra.)
Questo è tutto. Questo è ciò che ha funzionato per me.
Altri suggerimenti
Questo risolverà il tuo problema:
Copia il codice su Page_load di ASPX per passare il token autenticato al rapporto.
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);
}