Notes from Book: Pro ASP.NET 4

Click here to change the theme.

I have the book Pro ASP.NET 4 in C# 2010, Fourth Edition (there is a later edition), by Matthew MacDonald, Adam Freeman and Mario Szpuszta (ISBN 978-1-4302-2529-4; the fifth edition is 978-1-4302-4254-3). The first two chapters are about the history of ASP.NET, how to use Visual Studio and other things that most of us either already know or don't need to know. The following is notes from the first two chapters and I think is everything we need to know if we already know how to use Visual Studio and are familiar with .Net programming. Don't assume all of this is correct but I believe it is.

First let me provide a little introduction of a couple more issues about ASP.Net that are not made clear in the book and then the following notes might be a useful introduction to ASP.Net.

There is one thing that I learned very early about ASP.Net that is not obvious and that really helps. It is very simple yet it seems to be not stated explicitly in beginner articles. First I will say that everything ASP.Net does is done in the server. The thing I am getting at is that even when the "Runat=Client" attribute is used, the relevant processing is not done in the client. ASP.Net controls usually have "Runat=Server" but the Runat attribute can also be "Runat=Client" but even if "Runat=Client" is specified the relevant code is executed by ASP.Net in the server. I assume that "Runat=Client" just means to do something after the page has been processed but before it is sent to the client.

Something else that is simple yet usually not stated clearly enough is that C# code (inline or as code-behind) for a page can be put into the web site without compiling it first. C# code is compiled by ASP.Net in the server. There are exceptions, such as components, but for a beginner that is not relevant. Those of us familiar with other types of programming might not realize (I did not) that we don't really need to build an ASP.Net page before putting it into a web site.



ASP.NET does not support any application that does not use .NET. Therefore ASP.NET offers the advantages (features) of .NET applications.

HTML Controls VS. Web Controls

HTML Controls match HTML elements exactly and can be edited in HTML editors. HTML Controls are HTML elements with a "runat" attribute set to "server". Web Controls do not necessarily correspond to HTML elements and can consist of multiple HTML elements. Web control tags are the class name in the "asp" namespace, for example "asp:TextBox".

Websites and Web Projects

In Visual Studio the "File" | "New" sub-menu has "Project..." and "Web Site...".

When we create a web project (from "File" | "New" | "Project...") a project (.csproj) file is created in the manner that other projects are created. The project is compiled into a single assembly.

A website (created using "File" | "New" | "Web Site...") does not have a project (.csproj) file. (Except there is a hidden project file.) Every file in the website directory and the subdirectories are assumed to be a part of the web application. ASP.NET builds the website the first time a page is requested. Websites are newer, generally easier and should be used unless there is a specific reason to use a web project.

When creating a website, the following are the most common:

ASP.NET Web Site
A complete web site.
ASP.NET Empty Web Site
An empty website. It just has a Web.config file.
ASP.NET Dynamic Data Entites Web Site
Creates a website that uses an Entity Model to access a back-end database.
Dynamic Data LINQ to SQL Web Site
Creates a website that uses LINQ to SQL to access a back-end database.
WCF Service
Creates a library of server-side methods that remote clients use.
ASP.NET Reports Web Site
Creates a website that uses the ReportView control and SQL Server Reporting Services.

An empty website is a good way for a beginner to start, the other templates create sites containing more than what most beginners need and would probably be distracting.

Creating an empty site

The following assumes familiarity with VS and the HTML editor in VS.

Begin by creating a site in the local file system. Alternatively it is possible to create and develop a site over File Transfer Protocol (FTP).

It is not clear to me if the "Local IIS" option requires that "Management Compatibility" be installed and that Visual Studio be run as an administrator (page 26). I do not know if VS has a non-IIS server that it uses. In VS 2013 I do not seen an option for "Local IIS".

My experience with Visual Studio 2015 is that if we create a website without IIS being available then VS uses its own development server but if IIS is available then VS uses IIS.

Hosted by