Migrating from ASP to ASP.NET
Migrating from ASP to ASP.NET
This tutorial guides you through migrating a classic ASP application to ASP.NET. ASP and ASP.NET can run side-by-side on the same IIS server, so you can migrate incrementally.
Key Differences
| Feature | Classic ASP | ASP.NET |
|---|---|---|
| Language | VBScript / JScript (interpreted) | C# / VB.NET (compiled) |
| File extension | .asp | .aspx |
| Code structure | Inline with HTML | Code-behind files |
| State management | Session (InProc only) | Session (InProc, StateServer, SQL) |
| Data access | ADO (Recordset) | ADO.NET (DataReader, DataSet) |
| Error handling | On Error Resume Next | try/catch/finally |
| COM objects | Server.CreateObject() | Direct .NET classes (or COM Interop) |
Step 1: Set Up the ASP.NET Project
- Create a new ASP.NET Web Application in Visual Studio .NET.
- Copy static files (images, CSS, JavaScript) from the ASP application.
- Configure the connection string in
web.config:<configuration> <appSettings> <add key="ConnectionString" value="Server=SQLSERVER01;Database=FlamenetDB;Integrated Security=true;" /> </appSettings> </configuration>
Step 2: Convert Data Access
Replace ADO Recordset code with ADO.NET:
Before (ASP/ADO):
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("ConnString")
Set rs = conn.Execute("SELECT * FROM Products WHERE Active = 1")
Do While Not rs.EOF
Response.Write rs("ProductName") & "<br>"
rs.MoveNext
Loop
rs.Close : conn.Close
%>
After (ASP.NET/ADO.NET):
string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
SqlCommand cmd = new SqlCommand(
"SELECT ProductName FROM Products WHERE Active = 1", conn);
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Response.Write(reader["ProductName"] + "<br>");
}
}
}
Step 3: Replace COM Objects
Many COM objects used in ASP have .NET equivalents:
| ASP (COM) | ASP.NET (.NET) |
|---|---|
| Scripting.FileSystemObject | System.IO.File, System.IO.Directory |
| ADODB.Connection | System.Data.SqlClient.SqlConnection |
| MSXML2.DOMDocument | System.Xml.XmlDocument |
| CDO.Message (email) | System.Web.Mail.SmtpMail |
Migration Tips
- Migrate one page at a time — ASP and ASP.NET can run side-by-side
- Replace
On Error Resume Nextwith proper try/catch blocks - Use
Server.HtmlEncode()(ASP.NET version) instead of manual escaping - Move connection strings out of code into
web.config - Replace
SessionandApplicationobjects carefully — ASP.NET Session is not shared with classic ASP Session