Click here to Skip to main content
13,597,004 members
Click here to Skip to main content
Add your own
alternative version


119 bookmarked
Posted 26 Jun 2009
Licenced CPOL

Fully configured ASP.NET Membership Website Template

, 7 Jul 2009
Rate this:
Please Sign up or sign in to vote.
A pre-configured ASP.NET website containing a Master page, error handling, login / logout, and other boilerplate new project code.


The attached Visual Studio template is used to instantly create a website project that contains all the boiler plate code usually tedious to development (login/logout, displaying messages, Master page, CSS, JavaScript, error handling, changing passwords, etc...). This article provides a fully configured starting point for website project development with all that boiler plate code already completed.


The starting point in an application usually takes the longest getting the application configured properly to display messages in a uniform way, or to get the login features working. In order to speed up this portion of the application development process, I built this application template for use with Visual Studio 2008 to provide a stepping stone for all further website development.

If you don't know about Visual Studio project and item templates, surf over to here for an overview before continuing on. If you don't know about Base Pages and their uses, please surf over to here for an overview before continuing on. If you don't know about Master Pages and their uses, please surf over to here for an overview before continuing on.

Using the code

Place the attached .zip file into your Project Templates folder associated with Visual Studio 2008. The default location is {drive}:\...\Documents\Visual Studio 2008\Templates\ProjectTemplates. If you don't know where yours is, then open Visual Studio -> Tools -> Options -> Projects and Solutions, and look at the "user project templates location" textbox to see where Visual Studio is looking for custom project templates.

After placing the .zip file in your Project Templates folder, open Visual Studio 2008 and click File-> New Website. Name your website and click OK. A new website project will be in your solution, and it will contain the following items different than a normal website project:

  • Admin/{Default.aspx, web.config}
  • App_Code/{BasePage.cs, BaseMasterPage.cs}
  • App_Data/Web.sitemap
  • DefaultMaster.master
  • Global.asax
  • Login.aspx
  • Logout.aspx
  • web.config
  • Stylesheets/stylesheet.css
  • Scripts/JScript.js
  • Images/{Warning.gif, Error.gif, Information.gif}

Plus the normal Default.aspx but it is different in that it references the DefaultMaster.master as its Master page.

Go to the web.config file and change the connection string to point to a valid database that contains the ASP.NET membership tables. Confirm that the applicationName="" attribute that the membership and role sections of the web.config file points to are named correctly.

<roleManager enabled="true">

    <clear />
    <add name="AspNetSqlRoleProvider" 

         type="System.Web.Security.SqlRoleProvider, System.Web, 
               Version=, Culture=neutral, 


         applicationName="appName" />

    <clear />
      <add name="AspNetSqlMembershipProvider"

           type="System.Web.Security.SqlMembershipProvider, System.Web, 
                 Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"



           applicationName="appName" .../>


Add your header image to the Images folder. On the DefaultMaster.master page, add the ImageUrl="" attribute to the imgHeader image control to point to your header image.

Ensure the Regular Expression for passwords is correct in the web.config. The current expression requires a password between 8 and 15 characters, and requires the use of:

  1. a number (?=.*\d)
  2. a lower case letter (?=.*[a-z])
  3. an uppercase letter (?=.*[A-Z])
  4. and a special symbol (?=.*[!@#$%^&amp;*()_+])

    <add ... passwordStrengthRegularExpression="" />
    <add key="PasswordRegEx" 



Develop some way to log errors that occur in the application, and place that code in the Global.asax Application_Error method and the BasePage.HandleException(Exception ex) method:

public void HandleException(Exception ex)
    if (ConfigurationManager.AppSettings["Environment"] == "Development")
        Master.ErrorMessage = ex.Message;
        Master.ErrorMessage = "An unexpected error has occured in" + 
           "the application. If it continues, please contact the administrator.";
    // TODO Log the exception somehow, either with
    // Microsoft.Practices.EnterpriseLibrary.Logging or some other mechanism

void Application_Error(object sender, EventArgs e) 
    // Code that runs when an unhandled error occurs

    //get reference to the source of the exception chain
    Exception lastError = Server.GetLastError();
    Exception ex;
    if (lastError.InnerException != null)
        ex = lastError.InnerException;
        ex = lastError.GetBaseException();
    // TODO: Log the error somehow.

User Administration

Inside the Admin/Default.aspx page, there is a basic user administration piece that would allow someone with the Admin role to Approve/Unapprove, Unlock, and Add/Remove roles to users in the system.

Points of interest

Message are passed to the user via code-behind calls to:

  • base.InformationMessage = "My Information Message";
  • base.ErrorMessage = "My Error Message";
  • base.WarningMessage = "My Warning Message";

Although the "base." syntax is not necessary, I always place it so any future developer knows that some base page contains the definition for these properties and not the current page.

These message sections are initially invisible, and become visible when a string message passed to them (see BaseMasterPage.ErrorMessage for more details) sets EnableViewState = false, so they will disappear when the application does a postback.

The Master page utilizes the CodeFileBaseClass="BaseMasterPage" so the BaseMasterPage.cs file could expose the Labels and divs containing them via properties so a page could reference them.

<%@ Master Language="C#" AutoEventWireup="true" 

    Inherits="DefaultMaster" CodeFile="~/DefaultMaster.Master.cs"

    CodeFileBaseClass="BaseMasterPage" %>

The BasePage class hides the Page.Master property and casts the MasterPage as a BaseMasterPage so all a page has to reference is its ErrorMessage property.

public new BaseMasterPage Master { get { return (BaseMasterPage)base.Master; } }

public string ErrorMessage
  set { Master.ErrorMessage = value; }

Adding Just ASP.NET Membership and Roles Tables to a Database

Adding just the ASP.NET Membership tables to the database is easy to do, but requires you to use the command line of the aspnet_regsql.exe file. Look here for more information on using just the features you want for the ASP.NET membership.


  • June 26th, 2009 - Initial post.
  • July 7th, 2009 - Added User Admin section
</span />


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Stephen Inglish
Software Developer (Senior) Harland Financial Solutions
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionVisual Studo 2010 - Error Pin
mario.a.nunes12-Aug-13 3:36
membermario.a.nunes12-Aug-13 3:36 
GeneralMy vote of 5 Pin
Farhan Ghumra17-Jun-12 23:09
memberFarhan Ghumra17-Jun-12 23:09 
QuestionVisual Studi 2010 Pin
Mehdi Keramati8-Jul-11 14:02
memberMehdi Keramati8-Jul-11 14:02 
AnswerRe: Visual Studi 2010 Pin
zwalton1-Sep-11 8:54
memberzwalton1-Sep-11 8:54 
Generaldude great work Pin
bheeem26-Jan-11 2:36
memberbheeem26-Jan-11 2:36 
Questionhow can i protect the page from user without user in membership with c sharp Pin
desaihardikj@gmail.com9-Dec-10 14:09
memberdesaihardikj@gmail.com9-Dec-10 14:09 
QuestionHaving a problem in web.config Pin
dastarr18-Jun-10 15:00
memberdastarr18-Jun-10 15:00 
QuestionAdmin Account does not bring me to admin/default.aspx [modified] Pin
dastarr18-Jun-10 8:44
memberdastarr18-Jun-10 8:44 
GeneralMy vote of 1 Pin
Andrey Mazoulnitsyn9-May-10 1:17
memberAndrey Mazoulnitsyn9-May-10 1:17 
QuestionTemplate Pin
khaksaraziz13-Apr-10 18:20
memberkhaksaraziz13-Apr-10 18:20 
GeneralThanks Pin
the_bg14-Feb-10 9:11
memberthe_bg14-Feb-10 9:11 
QuestionVB Version? Pin
the_bg13-Feb-10 18:56
memberthe_bg13-Feb-10 18:56 
GeneralExactly what I was looking for Pin
slaphappy19751-Jan-10 15:34
memberslaphappy19751-Jan-10 15:34 
GeneralThanks Pin
RkHrd27-Nov-09 13:08
memberRkHrd27-Nov-09 13:08 
GeneralError: Could not load file or assembly 'System.Data.Entity' Pin
Behzad Ebrahimi24-Aug-09 18:52
memberBehzad Ebrahimi24-Aug-09 18:52 
GeneralRe: Error: Could not load file or assembly 'System.Data.Entity' Pin
Stephen Inglish26-Aug-09 9:32
memberStephen Inglish26-Aug-09 9:32 
GeneralRe: Error: Could not load file or assembly 'System.Data.Entity' Pin
benleo9-Aug-10 14:42
memberbenleo9-Aug-10 14:42 
GeneralDude, awesome. Pin
martenc15-Jul-09 14:54
membermartenc15-Jul-09 14:54 
GeneralRe: Dude, awesome. Pin
Stephen Inglish16-Jul-09 6:15
memberStephen Inglish16-Jul-09 6:15 
GeneralJust starting C# - Moving from vbscript Pin
Steve Krile14-Jul-09 1:55
memberSteve Krile14-Jul-09 1:55 
GeneralRe: Just starting C# - Moving from vbscript Pin
Stephen Inglish16-Jul-09 6:14
memberStephen Inglish16-Jul-09 6:14 
GeneralRe: Just starting C# - Moving from vbscript Pin
Steve Krile16-Jul-09 6:17
memberSteve Krile16-Jul-09 6:17 
GeneralRe: Just starting C# - Moving from vbscript Pin
Stephen Inglish17-Jul-09 2:16
memberStephen Inglish17-Jul-09 2:16 
GeneralThanks for this Template Pin
musacj2-Jul-09 2:19
membermusacj2-Jul-09 2:19 
GeneralGood Job! Pin
Moim Hossain26-Jun-09 10:44
memberMoim Hossain26-Jun-09 10:44 

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
Web03-2016 | 2.8.180621.3 | Last Updated 7 Jul 2009
Article Copyright 2009 by Stephen Inglish
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid