Main advantage of ASP.NET compared to ASP is object oriented approach to software development. Well, ASP does support classes. VBScript and JavaScript allowed writing code using classes and objects. You could write an object-oriented business logic layer but this layer was encapsulated into COM and COM+ (DCOM) objects.
This is the first time Microsoft made so cardinal change to its technology and almost completely abandoned support of earlier versions of ASP in ASP.NET. Although Microsoft does declare that you can gradually integrate ASP.NET code into an existing application written in ASP in reality that doesn’t make much sense.
Due to new approach to application development Microsoft developed a completely new class structure that can aid in development of different types of applications. This library is well structured and all classes inherit from one ancestor – Object class.
In ASP.NET major emphasis is on n-tier application development (i.e. separation of data presentation, business logic and data access). In ASP very often those layers were mixed and that lead to development of inefficient solutions with bulky architecture that were difficult to support. Object-oriented approach to solution architecture development allows slashing development time and scalability. Code reuse plays a significant role too. Usually application development is accompanied by development of service functions but in this case we can talk about development of universal classes to access business logic and data. For example, the following function in data access class is universal for all web applications.
|
public DataSet ExecuteSelect(String sqlQuery) { try { SqlCommand command = conn.CreateCommand(); command.CommandText = sqlQuery; if(conn.State!=ConnectionState.Open) conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter (sqlQuery, conn);
DataSet ds = new DataSet(); int rows = adapter.Fill (ds); return ds; } catch(SqlException exp) { throw new Exception(exp.Message); } finally { conn.Close(); } } |
This function provides access to data with ad-hoc queries and is universal for almost all (!) applications. The more applications you develop, the more universal classes you will have; thus you constantly speed up the process of development.
I would also want to draw your attention to data presentation layer. Microsoft developed a large number of controls that can be used in web applications. Using those controls allows developers to disengage themselves from HTML code management and use the same approach as in desktop application development. For example, you can use the following piece of code to display the content of a table on the page:
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Customers;", myConnection); DataSet ds = new DataSet(); da.Fill(ds, "Customers"); dataGrid.DataSource = ds; dataGrid.DataBind(); |
This code displays the content of “Customers” table on the page. All records are shown as a table with the same structure as in database table. With a few simple modifications you can add paging and automatic column data sorting. When using ASP.NET server controls developer doesn’t have to check the state of controls between user queries.
Control input validation is a big plus too. Built-in ASP.NET validation can save a lot of time and developers do not have to write their own functions as it was in the old ASP days. Built-in validation increases application reliability. We can do a double validation on client and server side.
Giving a general evaluation of ASP.NET technology I can single out the following:
- Increased speed of solution development through ASP.NET server controls usage and reuse of code
- Increased scalability thanks to n-tier architecture
- Easy maintenance
- Increased performance due to code compilation instead of ad-hoc script execution.