Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: pagelets or sub-pages


Message #1 by bpezzlo@p... on Mon, 16 Apr 2001 14:36:31
There are many ways to do this using script.  One possibly easy way is to 
use a bit of script in conjunction with the filesystem FSO object, and 
reading in only the relevant documents on an as needed basis.

However, I like the below way, which makes use of xsl / xml.  I just 
finished a similar implementation and it came out pretty nice -- getting a 
seperation of the data from the presentation of the data, and performing 
very well.  It will require some knowledge (or willingness to gain 
knowledge) in VB Scripting Component objects 
(http://msdn.microsoft.com/scripting/), XSL / XML (very basic knowledge 
here ... probably just for-each loop for now), SQL Server 2000, and asp.

Your goal is to have one master asp page that will become the home page of 
a users portal, where if the user has elected to see this data then the 
data will be displayed.  In this page you can put placeholders for each 
piece of optional data to be displayed.  Then, in a real basic sense, you 
can use something like the below to print the data if it should be printed:

(I assume a cache of the location of all XSL documents in an Application 
Level Variables to avoid multiple calls to Server.MapPath which can be 
slow ... basically somewhere in Application_OnStart set 
Application"MapPathXSL..." = Server.MapPath("./Inc/SomeXSLFile.xsl") )

Each item is displayed using syntax like the below
   Dim objXML, objXSL, strResult
   Set objXML = CreateObject("MSXML2.DOMDocument")
   Set objXSL = CreateObject("MSXML2.DOMDocument")
   
' In the appropriate news spot
If blnShowNews Then
   objXML.loadXML Application("XMLNews")  
   objXSL.load Application("MapPathXSLNews")
   strResult = objXML.transformNode(objXSL)
   response.write strResult
End If

' In the appropriate calendar spot
If blnShowCalendar Then
   objXML.loadXML Application("XMLCalendar")  
   objXSL.load Application("MapPathXSLCalendar")
   strResult = objXML.transformNode(objXSL)
   response.write strResult
End If

-----

For the project I just finished, I developed a portal using scripting com 
object representing a user and in this object I implement the asp 
interface, this allowed me to include the object in each page, and handle 
redirections to the login page if necessary.  It also managed the 
communication of the user to the database, where I had Stored Procedures 
holding most of the business logic.

The portal home page contained user customizable possibile items to view
(e.g. news, projects, calendar etc...).

I use an object to represent the member, and keep their member profile in 
an SQL Server 2000 database.  Each user must login in, and receive a 
temporary session id.  Inside the user object, I have a method to get the 
user profile back (this method calls a stored procedure which validates a 
session_id I store as a cookie, and if valid returns the users homepage 
profile with all necessary data else send user to the login page).  This 
way, in one round trip to the database I can return one string to this 
object, an xml string by way of ADODB.Recorset Method 'GetString', 
containing all data needed for the users homepage.  If the user's 
session_id was invalid, from the object (instead of the asp page) call 
response.redirect to send the user back the login page.  One of the 
parameters of their profile is a comma delimeted list of items they choose 
to keep on their home page.

  objCmd.Parameters.Append objPrmReturnValue
  objCmd.Parameters.Append objPrmSessionIN
  objCmd.Parameters.Append objPrmProfileDisplayOUT
  Set rs = objCmd.Execute
  if objPrmReturnValue.Value <> 0 then
     Response.Redirect Server.URLPathEncode("./Login.asp")
     'clean up objects here - set = nothing
  End If
  strProfileXML = rs.GetString
  rs.Close
  strHomeSetting = objPrmProfileDispayOut.Value
  vHomeSetting = Split(strHomeSetting)
  
I call Split(strHomeSetting) to turn the comma delimeted string into an 
array.

I then loop through this array to display the discrete pieces the user 
want on their home page like this:

dim i, max
max = UBOUND(vHomeSetting) - 1
if max > -1 'loop the array
   For i = 0 to max
     SELECT CASE vHomeSetting(i)
     Case "News"
        mstrNews = DisplayNews()  ' mstrNews maps to public property
                             ' LookupNews is a private function of object
     Case  "Calendar"
        mstrCalendar = DisplayCalendar
     Case  "Project"
        mstrProject = DisplayProject
     Case "ShowProfile"
        mstrProfile = DisplayProfile(strProfileXML)
     End Select
   next
end if


function get_News()
   get_News = mstrNews 'public properties of script object lool like this
end function

Function DisplayNews() 'an example of the xml cached in global.asa
   Dim objXML, objXSL
   objXML.loadXML Application("XMLNews")  
   RefreshNews objXML 'test if news should be refreshed, check @lastupdate
   objXSL.load Application("MapPathXSLNews")
   Set objXML = CreateObject("MSXML2.DOMDocument")
   Set objXSL = CreateObject("MSXML2.DOMDocument")
   strResult = objXML.transformNode(objXSL)
   DisplayNews = strResult
End Function

Function DisplayProfile (strProfile)
   ' an example from xml returned from sql server stored proc
   ' passed in as string and used to display profile
   Dim objXML, objXSL
   objXML.loadXML mstrProfileXML ' the XML returned from stored procedure
   objXSL.load Application("MapPathXSLProfile")
   Set objXML = CreateObject("MSXML2.DOMDocument")
   Set objXSL = CreateObject("MSXML2.DOMDocument")
   strResult = objXML.transformNode(objXSL)
   DisplayProfile = strResult
End Function


In the above you'll notice for stuff like news and calendar which are the 
same for all users, I store an XML string as an application level 
variable.  A property of the parent node of the xml document is 
last_update.  Before transforming the news, I validate the last update 
date ... if its older than one hour, I refresh the news with a hit to the 
database, otherwise I use the cached news found in the global.asa.






Now the asp page is very clean.
At the top I have a scipt
<SCRIPT RUNAT=SERVER>
   'use script tags insures script parsed before asp page itself is parsed
   Dim objUser
   Set objUser = CreateObject("PortalUser")
   objUser.LoadHomePage(Request.Cookies("Session_ID")
   ' if user doesn't have a valid session user redirected to login page
</SCRIPT>

Then in the appropriate places in your page you call

   <%=objUser.News%>
   <%=objUser.Calendar%>

These values will be empty if they don't want to see their calendar on the 
homepage, otherwise they will contain the calendar html.


This was a wordy response, I hope it makes sense.

Good luck,
Bruce






> Hi,
> 
> I have to develop a portal type page which will contain a number of
> sub-pages, each of which will be stored in a seperate asp/html file. 
These
> sub-pages will generally have dynamic content, and are optional, the user
> will be able to choose which ones they want to see.
> 
> I've looked at using server side includes to merge the pages. As there
> could be a large number of optional "pagelets" and the whole page will be
> built on loading, this will lead to one huge page in memory.
> 
> I've looked at using server.execute to conditionally include the
> "pagelets". There seems to be a problem with passing "paramaters" to the
> "pagelets" :
> - variables Dim'ed in the main page aren't available in the "pagelet"
> - request.form is readonly, and 
> - using the session object could have problems if two browsers are open
> sharing one cookie.
> 
> The paramaters will include context type values, eg. in this location,
> show 5 lines of detail.
> 
> Any advice on these and other approaches would be appreciated.
> 
> Thanks
> SteveW

  Return to Index