locked
The beginnings of a web portal using webparts & personalization... RRS feed

  • Question

  • User1068686496 posted
    Hello,

    I've just been playing around with the sample posted at
    http://msdn.microsoft.com/msdnmag/issues/05/09/WebParts/

    and I made a few small adjustments so that you can now:

    1. Dynamically add WebParts to a page.

    I created a dropdown list with all of the webparts used in the sample and another dropdown that gets populated with the friendly names of each WebPartZone on the page with an Add Button.

    Set Portal.aspx to be the startup page and run the application. By setting the HeaderText property of each WebPartZone you can provide friendly names for the areas that WebParts can be dragged to on your pages.

    2. Configured the FileBasedPersonalizationProvidor so that the ?PageId=xx querystring parameter is also used as part of the path when the ASP.NET personalization info is stored. This allows you to have portal pages like
    http://localhost/WingTipPortal/Portal.aspx?PageId=1
    http://localhost/WingTipPortal/Portal.aspx?PageId=2 etc

    It's almost kind of funny though, at the moment you can just change the number to 3, 4, 5 etc and you have another "blank" page instantly ready to add web parts to and personalize...

    This case would obviously need to be trapped and handled going forward though...

    3. Used the urlmappings attribute in the config file so that when you type in
    http://localhost/WingTipPortal/Test1.aspx for instance it rewrites the url to http://localhost/WingTipPortal/Portal.aspx?PageId=1

    but the user still sees http://localhost/WingTipPortal/Test1.aspx in the address bar of the browser.

    This can make your website look more attractive to end users... Of course after a postback it shows up as http://localhost/WingTipPortal/Portal.aspx?PageId=1 in the address bar....but hey... it's only early beginnings.

    4. The ability to change the Master page for a portal page at runtime... This was just quickly done and would need to be improved a lot for any real use...

    Basically, the test page has a simple combo with the available templates and the user can set the masterfile that the current page uses... like reskinning the whole page at runtime. )

    Anyway, I just thought I would share what I have done so far as I noticed a few people asking for a Portal Starter kit using WebParts and Personalization. The main trick to achieving this is by intercepting the path to be stored in the personalization tables (filesystem in this case).

    My adjustments are included in the attached source code. OOps. It seems I don't have permission to add attachments to posts on this form, so if anyone is interested in the src code let me know.

    Quick code snippets:

     In the App_Code/FileBasedPersonalizationProvider.cs file:

            protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path,
                           string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
            {
                // re-implement to retrieve page settings for user and shared data
                // equivalent of aspnet_PersonalizationAllUsers_GetPageSettings
                // and aspnet_PersonalizationPerUser_GetPageSettings
                //           

                path = ExtractCustomPath(webPartManager, path);
               .....

             }

            // Extract the ?pageid=1 part of the page url and append to the path variable
            // Example path    : ~/portal.aspx
            // Example page url: http://3031:localhost/WingTipPortal/portal.aspx?pageid=1
            private string ExtractCustomPath(WebPartManager webPartManager, string path)
            {           
                string url = webPartManager.Page.Request.Url.ToString(); // get the full url of the page

                Regex r = new Regex(@"(?<pageid>\?pageid=\d+)", RegexOptions.Compiled);

                string temp = "";    
          
                if (r.Match(url).Success)
                {
                    temp = r.Match(url).Result("${pageid}");
                }
                else
                {
                    temp = "";
                }

                return path + temp;
            }

    ...

    and

    pathConvertedToFileName = pathConvertedToFileName.Replace('?', '_');

    added to the ConstructUserDataFileName and ConstructAllUsersDataFileName functions..

    If anyone has done a better job of doing these things, then please share and post links and source code.

    Cheers,

    Darren


    Wednesday, February 1, 2006 11:14 PM

All replies

  • User16749350 posted

    Hi!

    I am working with Microsoft WebParts and getting Personalization Issues.

    It seems that u have a good application which will help to understand the personalization concept.

    So, can u send me that applicaiton to my personal mail id : lvprasady@hotmail.com.

    ur help always will be appreciated.

    Thanks and Regards,

    L V Prasad Yedla.

     

     

    Wednesday, May 3, 2006 7:19 AM