Hossein Zahed

Web Developer, Entrepreneur, Software Educator

ASP.NET Website vs Web Application Project

Introduction

This post explains about two project types in Visual studio i.e. Website and Web Application that we use to build the ASP.NET Applications and the fundamental differences between the two project types.

 

Background

Website project type was introduced in the VS 2005 and Web Application model introduced in VS 2003. Website project type is based on folder structure and does not require a project file. Later in VS 2005 sp1 project file was introduced for the VS 2005 website project type. Now in VS 2008 we can create both project types.

 

1. You can add Website or Web application project to your VS solution in VS 2008 as follows 

 

2. I have added two project types to the solution and it looks like the following

 

  • Fundamentally the behavior of the application types is same but website project type is folder based and WebApp is project type like normal project types in VS studio. In WebApplication project type project file defines the structure of the project.
  • WebSite project type contains the folders and anything that you put in the folder are dynamically compiled and be part in the website. More about ASP.NET Website Dynamic compilation here.
  • WebApplication project type contains the designer for the ASPX page and you can find the bin folder which contains the compiled assembly.
So First difference can be summarized like ASP.NET website project type is dynamic and WebApp is more like structured.
 
3. When you add a class file to the website project it will prompt you that it will place the file in App_code folder under root.
Notice In website project type namespace won't add to the class by default however you can define the namespaces explicitly where as in WebApp it creates the namespace for the class file when you added it to the project.
 
4. WebApp project type is restricted to one language where as Website you can add different language files to the App_Code folder which compiles the files dynamically.
 
5. Referring a user control in WebApp is straight forward.You can define the properties and can be accessed in class files like any other objects where as in website it is not.
 
6. We can put multiple language files in the Website but those files needs to be in same folder. If you change the location of the file then you need to mention in the Web.Config file as follows.  
<codeSubDirectories> 
<add directoryName="Testfolder"/> 
</codeSubDirectories>
  In compilation process you will have the finer degree of control in WebApp and it is not in Website because everything is dynamically compiled.
 
7. When you deploy the WebApps you can just copy the Compiled Assembly and Visual elements to the IIS folder where as in Website you need to copy everything to the IIS to work.
 
8. You can see the following dialogue box when you publish the files in Website
 

If you select the precompiled option then you will find the precompiled folder in the published location there you find the multiple assemblies for each folder in the website.

 

9. If you use WebApplication project you can not access Profie at design time a workaround solution can be found here.

 

10. The following link helps you to choose which project type you have to user for the developing web applications.

Membership Provider and Role Manager

Introduction

ASP.NET provides all the features we need to use a database to store all kinds of security, user, and role membership details. It also provides a series of server controls that help we build the pages that users need and that administrators require creating accounts, change passwords, and maintain the login information and role membership for each user. The two features of ASP.NET that support this are:

  • The membership provider and the associated database tables and procedures
  • The role manager and its associated database tables and procedures

 

Membership Provider Configuration

The ASP.NET membership provider manages the tables in the ASP.NET application database that store details of the users we define for Web site. The <membership> section of web.config defines the configuration of the membership provider, including the connection to the database using <membership> element (located within the <system.web> section) and the content.

The <membership> element consists of a series of one or more <add> elements within the <providers> section, each of which defines the parameters for a provider that will be available for the membership system to use. By default, it includes just the first one, named AspNet-SqlMembershipProvider. We have added two more to the list to demonstrate how we can choose a different configuration for your providers, if required.

The connectionStringName attribute refers to a value in the <connectionStrings> section of this web.config file, or a value defined in a web.config file nearer the root folder of this application. The remaining attributes set specific properties of the provider that control how ASP.NET pages and controls can interact with it. 

<system.web>
  ...
  <membership>
    <providers>
      <add name="AspNetSqlMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, ..."
           connectionStringName="LocalSqlServer"
           applicationName="/"
           enablePasswordRetrieval="false"
           enablePasswordReset="true"
           requiresQuestionAndAnswer="true"
           requiresUniqueEmail="false"
           passwordFormat="Hashed"
           maxInvalidPasswordAttempts="5"
           minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1"
           passwordAttemptWindow="10"
           passwordStrengthRegularExpression="" />
      <!-- following added to use SQL Server 2005 database -->
      <add name="Sql2005MembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, ..."
           connectionStringName="SqlServer2005"
           ... />
      <!-- following uses remote SQL Server attached database -->
      <add name="Sql2005RemoteMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, ..."
           connectionStringName="Sql2005Remote"
           ... />
    </providers>
  </membership>
  ...
</system.web>

 

Specifying the Database Connection Strings

The <add> elements in the <membership> section of web.config correspond to values defined in the <connectionStrings> section. These are, in order:

  • A connection to the local SQL Server Express Edition database that is an optional component we can install with Visual Studio 2005. SQL Server 2005 and SQL Server Express Edition can auto-attach an .mdf database file as they connect. The AttachDBFilename and User Instance properties of the connection string specify that this will occur, and they provide the required location and instance information.  
  • A connection to a local instance of SQL Server 2005 using the database auto-attach feature. 
  • A connection to a remote SQL Server that has the database already attached, specifying the login details required to connect to this database.

Notice that all specify the database named aspnetdb in the file named aspnetdb.mdf. This is the default database name, though we can specify a different name if we wish when we create the database. The physical location, when using the auto-attach feature, is the App_Data subfolder within the root of the Web site or Web application virtual directory.

Note that the <connectionStrings> element does not reside within the <system.web> section, because it stores connection strings for all other types of applications (such as Windows Forms applications) as well as Web Forms pages.

<connectionStrings>
  <add name="LocalSqlServer"
       connectionString="data source=.\SQLEXPRESS;
                         Integrated Security=SSPI;
                         AttachDBFilename=|DataDirectory|aspnetdb.mdf;
                         User Instance=true"
       providerName="System.Data.SqlClient" />
 
  <!-- following added to use SQL Server 2005 database -->
  <add name="SqlServer2005"
       connectionString="data source=localhost;
                         Integrated Security=SSPI;
                         AttachDBFilename=|DataDirectory|aspnetdb.mdf;
                         User Instance=true"
       providerName="System.Data.SqlClient" />
 
  <!-- following added to use remote SQL Server attached database -->
  <add name="Sql2005Remote"
       connectionString="data source=myremoteserver;
                         Initial Catalog=aspnetdb;
                         User ID=myusername;
                         Password=secret"
       providerName="System.Data.SqlClient" />
 
</connectionStrings>

 

Role Manager Configuration

Having looked at the configuration of the built-in membership provider in ASP.NET, we will not be surprised to discover that the built-in role 

provider follows much the same pattern. The <roleManager> section of web.config defines a list of providers that are available. It contains, by default, two providers:

  1. The SqlRoleProvider uses the same database as the membership provider to hold details of the roles and role membership, and we can configure the roles and members using the ASP.NET Web Site Administration Tool. 
  2. The WindowsTokenRoleProvider is a read-only provider, and exposes information about roles for a specific Windows user account. It takes this information from the account groups held in Active Directory or on your server or local machine, depending on the configuration. We cannot create, add, or delete roles with this provider.
<system.web>
  ...
  <roleManager enabled="true">
    <providers>
 
      <add name="AspNetSqlRoleProvider"
           type="System.Web.Security.SqlRoleProvider ..."
           connectionStringName="LocalSqlServer"
           applicationName="/" />
      <add name="AspNetWindowsTokenRoleProvider"
           type="System.Web.Security.WindowsTokenRoleProvider, ..."
           applicationName="/" />
      <!-- following added to use SQL Server 2005 database -->
      <add name="Sql2005RoleProvider"
           type="System.Web.Security.SqlRoleProvider, ..."
           connectionStringName="SqlServer2005"
           applicationName="/" />
      <!-- following uses remote SQL Server attached database -->
      <add name="Sql2005RemoteRoleProvider"
           type="System.Web.Security.SqlRoleProvider, ..."
           connectionStringName="Sql2005Remote"
           applicationName="/" />
    </providers>
  </roleManager>
  ...
</system.web>

 

Special folders in ASP.NET

With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. 

ASP.NET defines several special folders. When a new Web site is created the App_Data folder is created by default; it can contain a SQL Server 2005 Express Edition database, another database, or an XML data file that will be used in the Web site. 

From ASP.NET 2.0 versions Microsoft provided 8 integration directories to integrate different resource in your application. 

It is also called Data Directory. 

Special folders that exist in ASP.NET that can be added to your Web site are as below: 

 

App_Browsers 

ASP.net reserve this folder name for storing browser definition files. Browser definition files are used to determine the client browser capabilities. Browser definition files have .browser extension. 

These files are often used to help support mobile application.

 

App_Code 

App_code folder can contain source code for utility classes as well business objects (.cs, .vb and .jsl files). Classes that are present in App_Code folder are automatically complied when your web application complied. 

Arbitrary file types can be placed in the App_Code folder to create strongly typed objects. 

For example: placing Web service files (.wsdl and .xsd files) in the App_Code folder creates strongly typed proxies. Code present in App_Code is automatically referenced by ASP.net Application.

 

App_Data 

App_Data is used to store file that can be used as database files (.mdf and xml files). 

App_Data folder is used by ASP.NET application for storing ASP.NET application local database. Developers can also use this folder for storing data for their ASP.NET Application.

 

App_GlobalResources 

App_GlobalResources folder contains resources (.resx and .resources files) that are compiled into assemblies and have a global scope. 

Resource files are used to externalize text and images from your application code. This helps you to support multiple languages and design-time changes without recompilation of your source code. 

Resource files are strongly typed and can be accessed programmatically.

 

App_LocalResources 

App_LocalResources folder contains resources (.resx and .resources files). The same files that are being contained by App_GlobalResources but files located in this folder are only available to a particular project, web page, master page or web user control.

 

App_Themes 

Contain subfolders that each defines a specific theme or look and feel for you Web site. A these consist of files (such as .skin, .css and image files) that defines the appearance of Web pages and controls.

 

App_WebReferences 

Contains Web references files (.wsdl, .xsd, .disco, and .discomap files) that define references to Web services.

 

Bin 

Bin folder contains compiled assemblies (.dll files) for code that you want to reference in your application. Assemblies in Bin folder are automatically reference in your application. 

Special folders can be added to a Web site from the Visual Studio menu system. Typically this involves right-clicking the Web Application project and selecting Add ASP.NET folder.