Click here to Skip to main content
14,022,423 members
Click here to Skip to main content
Add your own
alternative version


188 bookmarked
Posted 15 Oct 2003

Personal .NET Portal

, 16 Oct 2003
Rate this:
Please Sign up or sign in to vote.
A Personal .NET Portal with Forms Authentication and XML Files for storage.


This article describes how I build my Personal Portal (in other words: a Homepage). The idea was to develop a Portal that is easy to deploy (e.g. no Database) and easy to use.

These technical problems are solved in this solution

  • Storage The portal doesn't use a database. Instead XML-Files are used. Reading/Writing is done with the XML Serializer and Datasets.
  • Dynamically loading of Web User Controls The portal has Tabs and Modules. Modules are Web User Controls which are loaded at runtime. The definition is stored in a XML File.
  • Authentication Forms Authentication is used. Users and Roles are stored in a XML File.
  • HttpHandler A HttpHandler is used to access Tab-Pages.


First I wanted to use the IBuySpy Portal. But it isn't (or wasn't) free and uses a database. After some searching at Codeproject and Sourceforge I decided to implement my own Portal.

This Project is hosted at Sourceforge. I would be happy about feedback and suggestions . Also new modules or improvements are welcome. A Demo Portal can be found here .

Using the code

Feel free to use the Portal under the GPL License or code snippets freely.


A Portal has Tabs. Each Tab can have Sub-Tabs and Modules. Modules are providing content. A Module can be placed right, in the middle or on the left side on a Tab.

A Module consists of a View Web User Control and a Edit Web User Control. The edit control is optional. Both controls are derived from the Module/EditModule class. Those classes are providing information (Reference, Name, etc.) and a configuration infrastructure. Modules are located in the Modules/<ModuleName> directory.

Tabs and Modules have Roles assigned. Users in those roles may view/edit Tabs/Modules. There are four built-in roles:

  • Admin - Administrator Role. May edit/view everything
  • User - Signed in User
  • Everyone - Signed in User or Anonymous User
  • Anonymous - Not signed in User

The Portal definition and Users are stored in a XML File.

Currently there is a "Frame" and a "Table" version (configured in the web.config file). This is how the Portal is rendered: In Frames or in a Table.


Class Name Description
PortalDefinitionThis is the main Portal Definition class. It contains various helper functions and a list of Tabs.
PortalDefinition.TabThe Tab Definition. A Tab has a Name, Reference, Roles, Sub Tabs and left/middle/right Modules.
PortalDefinition.ModuleA Module has a Name, Reference and Roles.
PortalDefinition.RoleA Role is just a Name and Base Class for View or Edit Roles
PortalDefinition.EditRoleEdit Role.
PortalDefinition.ViewRoleView Role.
UsersUser/Roles Dataset.
ModuleSettingsDefines Module Settings like the Module Control Name.
EditLinkRenders the Edit Link.
ModuleFailedRenders a "Module failed to load".
ModuleHeaderRenders the Module Header.
OverlayMenuRenders a Menu.
OverlayMenuItemRenders a Menu Item.
PortalTabThis is the main Protal Render Control!
TabMenuRenders the Tab Menu.
TabPathRenders the current Tab Path.
TabHttpHandlerThe HttpModule for "translating" URLs.
HelperCommon Helper Class.
UserManagementUsermanagement Methods.
ConfigConfiguration Helpers.
EditModuleBase Class for Module Edit Controls.
ModuleBase Class for Module View Controls.

ASPX-Pages are used as container for Web User Controls. They have hardly program logic.


Two things must be stored: the Portal Definition and Users/Roles.

The Portal definition is stored with the XML-Serializer.

[XmlRoot("portal"), Serializable]
public class PortalDefinition
  // Static Serializer
  private static XmlSerializer xmlPortalDef = 
     new XmlSerializer(typeof(PortalDefinition));
  // Loads the Portal Definition
  public static PortalDefinition Load()
    // Create a Text Reader which reads the file
    XmlTextReader xmlReader = new XmlTextReader(
    // Deserialize
    PortalDefinition pd = (PortalDefinition)xmlPortalDef.Deserialize(
    // Close the file

    return pd;
  // Saves the Portal Definition
  public void Save()
    // Create a Text Writer which writes the file
    XmlTextWriter xmlWriter = new XmlTextWriter(
          Config.GetPortalDefinitionPhysicalPath(), System.Text.Encoding.UTF8);
    // Set Formating
    xmlWriter.Formatting = Formatting.Indented;
    // Serialize
    xmlPortalDef.Serialize(xmlWriter, this);
    // Close the file

Users are stored in a Dataset

public class UserManagement
  // Reads the User Dataset from a file
  public static Users GetUsers()
    Users u = new Users();
    return u;
  // Writes the User Dataset to a file
  public static void SetUsers(Users u)


Forms Authentication is used, but I can imagine that Windows Authentication would also work.

First, in the Login Module, your credentials are validated. This is done through a helper method.


void OnLogin(object sender, EventArgs args)
  if(Portal.UserManagement.Login(account.Text, password.Text))
    lError.Text = "Invalid Login";
public static bool Login(string account, string password)
  // Load Dataset
  Users u = GetUsers();

  // Find user
  Users.UserRow user = u.User.FindBylogin(account.ToLower());
  if(user == null) return false;
  // Check password
  if(user.password != password) return false;

  // Set Authentication Cookie
  FormsAuthentication.SetAuthCookie(account, false);
  return true;

When a Http-Request occurs, Global.Application_AuthenticateRequest is called. There the user roles are set.

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    // Read users roles
    string[] roles = UserManagement.GetRoles(
    // Set a new Principal with the proper roles
    HttpContext.Current.User = new GenericPrincipal(
      HttpContext.Current.User.Identity, roles);
public static string[] GetRoles(string account)
  // Load the User Dataset
  Users u = GetUsers();

  // Find the current user
  Users.UserRow user = u.User.FindBylogin(account.ToLower());
  if(user == null) return new string[0];

  // Read users roles and add to a string array
  Users.UserRoleRow[] roles = user.GetUserRoleRows();
  string[] result = new string[roles.Length];  
  for(int i=0;i<roles.Length;i++)
    result[i] = roles[i];

  return result;

Loading Controls Dynamically

The PortalTab.ascx Web User Control renders the Tabs. The current Tab reference is passed as a URL Parameter. Modules are loaded in the OnInit Event so they can process their OnLoad Events.

public abstract class PortalTab : System.Web.UI.UserControl
  // Table Cells where the Modules are rendered
  protected HtmlTableCell left;
  protected HtmlTableCell middle;
  protected HtmlTableCell right;

  // Renders a Module Column
  private void RenderModules(HtmlTableCell td, PortalDefinition.Tab tab,
           ArrayList modules)
    // Hide the cell if there where no Modules
    if(modules.Count == 0)
      td.Visible = false;
    foreach(PortalDefinition.Module md in modules)
      // Only if the User has view rights
      if(UserManagement.HasViewRights(Page.User, md.roles))

        // Initialize the Module
        Module m = null;

        // Load the Module
        if(md.moduleSettings == null)
          m = (Module)LoadControl(Config.GetModuleVirtualPath(md.type) 
                  + md.type + ".ascx");
          m = (Module)LoadControl(Config.GetModuleVirtualPath(md.type) 
                  + md.moduleSettings.ctrl);
        // Initialize the Module
        m.InitModule(tab.reference, md.reference, 
          UserManagement.HasEditRights(Page.User, md.roles));
        // Each Module can decide if it wants to be rendered. 
        // The Login Module does so.
          // Add Module Header
          ModuleHeader mh = (ModuleHeader)LoadControl("ModuleHeader.ascx");

          // Add Module
          HtmlGenericControl div = new HtmlGenericControl("div");
          div.Attributes.Add("class", "Module");

  // Called by the ASP.NET Framework
  override protected void OnInit(EventArgs e)
    PortalDefinition.Tab tab = PortalDefinition.GetCurrentTab();

    // Check user rights
    if(UserManagement.HasViewRights(Page.User, tab.roles))
      // Render
      RenderModules(left, tab, tab.left);
      RenderModules(middle, tab, tab.middle);
      RenderModules(right, tab, tab.right);

    // CODEGEN: This call is required by the ASP.NET Web Form Designer.


The HttpHandler is used to "translate" URLs from "http://server/Portal/" to "http://server/Portal/RenderTable.aspx?TabRef=main". This is interesting if you want to analyze your Web Server Log Files.

To get this work you must add this to your web.config file

    <add verb="*" path="*.tab.aspx" type="Portal.TabHttpHandler, Portal" />

".tab.aspx" is used as a extension, because otherwise you have to reconfigure your IIS.

This HttpModule does nothing else than a simple Server.Transfer

public class TabHttpHandler : IHttpHandler, IRequiresSessionState
  public void ProcessRequest(HttpContext context) 
    // Parse the URL and extract the Tab Reference
    string path = context.Request.Url.AbsolutePath.ToLower();
    string tabRef = path.Substring(path.LastIndexOf("/") + 1); 
          // get ""
    tabRef = tabRef.Substring(0, tabRef.LastIndexOf(".tab.aspx")); 
          // get "TabRef"

    // Save URL Parameter
    Hashtable r = new Hashtable();
    foreach(string key in context.Request.QueryString.Keys)
      r[key] = context.Request[key];

    r["TabRef"] = tabRef;
    // Read the configuration to determinate the current main page
    string url = Portal.API.Config.GetMainPage();
    // Build the URL
    bool firstParam = true;
    foreach(DictionaryEntry e in r)
        url += "?";
        firstParam = false;
        url += "&";
      url += e.Key.ToString() + "=" + e.Value.ToString();
    // Redirect
  public bool IsReusable
      return true;

Creating a Module

Creating a Module is simple. Just create a directory in the Modules directory and put there the View- and Edit Web User Control. The Controls names must be (or can be reconfigured) <ModuleName>.ascx and Edit<ModuleName>.ascx.


Just derive form Portal.API.Module or Portal.API.EditModule and implement "IsVisible" if necessary.

The Module Class provides some properties and methods which describes the Module.

Current Module Settings

Name Description
IsVisibleCan be overridden. Tells the Portal Framework if the Module should be rendered or not.
TabRefThe current Tab Reference. This is a unique string.
ModuleRefThe current Module Reference. The Module Reference is not necessarily unique. TabRef + ModuleRef is unique.
ModuleVirtualPathThe virtual path to the Module.
ModulePhysicalPathThe physical path to the Module.
BuildURLBuild a URL to the current Page. Use this method to implement Modules that needs URL Parameter.
ModuleHasEditRightsTrue if the current user has edit rights.


Each Module has the responsibility to store its configuration and state. The Portal API provides some Helper Methods.

Name Description
ModuleConfigFilePhysical Path to the configuration file. (<ModulePhysicalPath>\Module_<ModuleRef>.config)
ModuleConfigSchemaFilePhysical Path to the configuration schema file. (<ModulePhysicalPath>\ Module_<ModuleRef>.configModule.xsd)
ReadCommonConfigReads (XML Deserialize) the common configuration file.
ReadConfigReads (XML Deserialize/Dataset) the configuration file.
WriteConfigWrites (XML Serialize/Dataset) the configuration file.

Furthermore each Module can a configure its control files. These settings are stored in the "ModuleSettings.config" file.


The "ctrl" Tag defines the View Web User Control. The "editCtrl" Tag can contain "none", which means: there is no Edit Control. E.g. the Login or HitCounter Modules are using this.

Example (Simple Html Module)

This simple Module reads a .htm file and renders it into a DIV Tag.

View Control Html.ascx:

<%@ Control Language="c#" Inherits="Portal.API.Module" %>
<%@ Import namespace="System.IO" %>
<script runat="server">
    private string GetPath()
        return ModulePhysicalPath + ModuleRef + ".htm";

    void Page_Load(object sender, EventArgs args)
        // Open file            
            FileStream fs = File.OpenRead(GetPath());
            StreamReader sr = new StreamReader(fs);
            content.InnerHtml = sr.ReadToEnd();

<div id="content" runat="server">

Edit Control EditHtml.ascx:

<%@ Control Language="c#" autoeventwireup="true" 

    Inherits="Portal.API.EditModule" %>
<%@ Import namespace="System.IO" %>
<script runat="server">

    private string GetPath()
        return ModulePhysicalPath + ModuleRef + ".htm";

    void Page_Load(object sender, EventArgs args)
            // Open file            
                FileStream fs = File.OpenRead(GetPath());
                StreamReader sr = new StreamReader(fs);
                txt.Text = sr.ReadToEnd();
    void OnSave(object sender, EventArgs args)
        FileStream fs = null;
            fs = new FileStream(GetPath(), FileMode.OpenOrCreate, 
                 FileAccess.ReadWrite, FileShare.None);
            fs.SetLength(0); // Truncate
            StreamWriter sw = new StreamWriter(fs);
            if(fs != null)

<asp:TextBox id="txt" Width="100%" Height="300px" 

    TextMode="MultiLine" Runat="server"></asp:TextBox>
<asp:LinkButton CssClass="LinkButton" runat="server" OnClick="OnSave">
    Save & Back</asp:LinkButton>

Work from others

Not all work is from me. I took some code from others and made Modules. Thanks!


  • 17.10.2003 Version 1.0.2 uploaded. TreeWebControlPrj is now in the zip file.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Arthur Zaczek
Founder OG
Austria Austria
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
chandruvelan7-Mar-12 0:03
memberchandruvelan7-Mar-12 0:03 
Generalgreat app Pin
Imade11-May-11 6:30
memberImade11-May-11 6:30 
General.net2.0 error Pin
longren62927-May-07 23:02
memberlongren62927-May-07 23:02 
QuestionVB.Net version? Pin
Hasan Bazerbashi4-Sep-05 2:14
memberHasan Bazerbashi4-Sep-05 2:14 
AnswerRe: VB.Net version? Pin
Anonymous4-Sep-05 5:56
memberAnonymous4-Sep-05 5:56 
AnswerRe: VB.Net version? Pin
Maruf Maniruzzaman23-Sep-07 0:43
memberMaruf Maniruzzaman23-Sep-07 0:43 
GeneralError message Pin
Rahman Mahmoodi26-Aug-05 4:30
memberRahman Mahmoodi26-Aug-05 4:30 
GeneralPortal Language Pin
rafael35512-Aug-05 8:55
memberrafael35512-Aug-05 8:55 
GeneralRe: Portal Language Pin
Anonymous14-Aug-05 1:18
memberAnonymous14-Aug-05 1:18 
GeneralRe: Portal Language Pin
rafael35515-Aug-05 7:21
memberrafael35515-Aug-05 7:21 
GeneralGreat job Pin
paulsoren29-Jun-05 11:12
memberpaulsoren29-Jun-05 11:12 
Generallogin fails on redirected site Pin
Anonymous15-Jun-05 11:42
memberAnonymous15-Jun-05 11:42 
GeneralTabs don't wrap Pin
Christopher Scholten13-Jun-05 17:12
professionalChristopher Scholten13-Jun-05 17:12 
QuestionMSI Installation Package? Pin
venkriss13-Apr-05 4:12
membervenkriss13-Apr-05 4:12 
AnswerRe: MSI Installation Package? Pin
Anonymous14-Apr-05 10:07
memberAnonymous14-Apr-05 10:07 
QuestionImageBrowser ? Pin
dbui23-Mar-05 12:41
memberdbui23-Mar-05 12:41 
AnswerRe: ImageBrowser ? Pin
dbui24-Mar-05 8:24
memberdbui24-Mar-05 8:24 
GeneralSub Tab don't display Pin
Fabio97217-Mar-05 22:09
memberFabio97217-Mar-05 22:09 
GeneralRe: Sub Tab don't display Pin
Arthur Zaczek18-Mar-05 1:12
memberArthur Zaczek18-Mar-05 1:12 
GeneralExcellent !!! Pin
Fabio97217-Mar-05 10:51
memberFabio97217-Mar-05 10:51 
GeneralProblem with &quot;; Pin
Anonymous1-Mar-05 15:38
memberAnonymous1-Mar-05 15:38 
GeneralRe: Problem with &quot;; Pin
Anonymous1-Mar-05 15:50
memberAnonymous1-Mar-05 15:50 
GeneralLogin problem Pin
mitmil6-Feb-05 12:34
membermitmil6-Feb-05 12:34 
GeneralRe: Login problem Pin
mitmil10-Feb-05 9:50
membermitmil10-Feb-05 9:50 
GeneralFreeTextBox Pin
apagnier19-Dec-04 4:21
memberapagnier19-Dec-04 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190417.4 | Last Updated 17 Oct 2003
Article Copyright 2003 by Arthur Zaczek
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid