Logon.csp

To download the CSP files from this tutorial, click TutorialSamples.zip. For more information, see Code examples.

<%@ Language=JavaScript%>

<HTML>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

<link REL=STYLESHEET TYPE='text/css' HREF='tut.css'>

<!-- #include file=helper_js.csp -->

<BODY>

<%

function Main()

{

    var UserID, Password, APS, Aut;

    

    //Retrieve the user information from the form

    //on the previous page.

    APS = Request.QueryString.Item("APS");

    UserID = Request.Form.Item("UserID");

    Password = Request.Form.Item("Password");

    

    //Authentication type.

    Aut = Request.Form.Item("Aut");


    Response.Expires = 0;

    

    var SessionManager;

    

    try

    {

       //Create an Enterprise SessionManager.

       SessionManager = Server.CreateObject("CrystalEnterprise.SessionMgr");

    }

    catch(e)

    {

       Response.Write ("Couldn't create SessionManager");

       //Handle error here.

       return;

    }

    

    var Sess;

    try

    {

       //Log the user on to Crystal Enterprise.

       Sess = SessionManager.Logon(UserID, Password, APS, Aut);

    }

    catch(e)

    {

       //Check to see if logon failed.

       //If the logon failed, show a message box with an error description.

       Response.Write ("<SCRIPT language=\"javascript\"> " +

        " alert (\"Sorry - you could not be logged on to " +

        "this server. Ensure that your user name and " +

        "password, as well as the APS name are correct. " +

        "\");</SCRIPT>");

        

       //Redirect the user back to the logon page.

       Response.Write ("<META HTTP-EQUIV='refresh' CONTENT='0;URL=LogonForm.csp'");

       return;

    }

    

    var IStore;

    var LogonTokenMgr;


    //Create the InfoStore object.

    IStore = Sess.Service ("", "InfoStore");


    //Store the InfoStore object in the session using the helper functions.

    SetSession("IStore",IStore);

    

    //Retrieve the LogonTokenManager.

    LogonTokenMgr = Sess.LogonTokenMgr;

        

    //Retrieve a Logon Token and store it in the user's cookie file for later use.

    SetCookie("LogonToken",LogonTokenMgr.CreateLogonTokenEx("", 60, 100));

    

    //Redirect the user to the site's home page.

    Response.Write("You have been logged on to Enterprise");    

    Response.Redirect ("Home.csp?FolderID=0");

}


Main();

%>

</BODY>

</HTML>







Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com