Webpart code to dynamically load a page viewer webpart to display a requested page

    1:  using System;
    2:  using System.Runtime.InteropServices;
    3:  using System.Web.UI;
    4:  using System.Web.UI.WebControls;
    5:  using System.Web.UI.WebControls.WebParts;
    6:  using System.Xml.Serialization;
    7:   
    8:  using Microsoft.SharePoint;
    9:  using Microsoft.SharePoint.WebControls;
   10:  using Microsoft.SharePoint.WebPartPages;
   11:  using System.Xml;
   12:  using System.ComponentModel;
   13:   
   14:  namespace WebPart1
   15:  {
   16:      [Guid("8517b24e-202c-4319-8960-303996a3fdb6")]
   17:      public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
   18:      {
   19:          public WebPart1()
   20:          {
   21:              this.ExportMode = WebPartExportMode.All;
   22:          }
   23:   
   24:          protected override void CreateChildControls()
   25:          {
   26:              base.CreateChildControls();
   27:   
   28:              // TODO: add custom rendering code here.
   29:              // Label label = new Label();
   30:              // label.Text = "Hello World";
   31:              // this.Controls.Add(label);
   32:          }
   33:   
   34:          protected override void Render(HtmlTextWriter writer)
   35:          {
   36:              SPWeb web = SPContext.GetContext(this.Context).Web;
   37:              web.AllowUnsafeUpdates = true;
   38:              SPUser user = web.CurrentUser;
   39:              SPWebPartCollection collection = web.GetWebPartCollection("default.aspx", Storage.Personal);
   40:              writer.Write(user.LoginName);
   41:              PageViewerWebPart lobjWebPArt = new PageViewerWebPart();
   42:              //Change to the JSP URL or your web Application
   43:              lobjWebPArt.ContentLink = "https://www.microsoft.com?SID=" + user.LoginName.ToString() + "&VIEW=domain";
   44:              collection.Add(lobjWebPArt);web.Dispose();
   45:          }
   46:      }
   47:  }

:: Please note that I would have just uploaded my initial code and you might want to consider proper optimization of the code and disposal of objects properly. I might not have updated the latest code here.