Using a Text Editor to Develop and Deploy an ASP.NET Web Application
 
Published: 10 Oct 2007
Abstract
In this article, Andrew examines the usage of the freeware Crimson Editor to show how to develop, compile, deploy (FTP), and launch an ASP.NET web application in a browser.
by Andrew Mooney
Feedback
Average Rating: 
Views (Total / Last 10 Days): 37071/ 77

Introduction

Have you ever developed a web application without an IDE, syntax highlighting and IntelliSense? If so, then you were probably using a text editor like notepad to create these applications. And you might be happy to know that this is still possible even with Microsoft's .NET framework.  Let us walk through how to use a text editor to develop and deploy an ASP.NET web application. For this article I will be using Crimson Editor, a free text editor, but you can use any text editor you prefer.

Requirements

There are a few requirements before we begin. You do not need Microsoft Visual Studio. However, you will need a web server that supports ASP.NET. You can choose either IIS 5.1 or the development web server that is included in the .NET Framework SDK 2.0. This file, named WebDev.WebServer.exe, is also installed with Visual Web Developer and Visual Studio 2005. You can check to see if this file is installed by looking in directory C:\Windows\Microsoft.NET\Framework\v2.0.50727.

1. Windows XP Professional

2. Web Server IIS 5.1 or WebDev.WebServer.exe (from .NET Framework SDK)

3. The .NET Framework 2.0 Runtime or SDK (if you want to use WebDev.WebServer.exe)

4. Any Text Editor

Why I Prefer To Use Crimson Editor

There are several reasons why I prefer to use Crimson Editor. First of all, the price is right; it is free! Also, I find the syntax highlighting files, which can be downloaded, for C# and VB.NET code to be very useful. Crimson Editor lets you add shortcuts that allow you to execute external programs with arguments. This feature will come in handy later when we want compile and deploy our web application. A directory and file browser is included that has a right click menu that contains a Shell Execute command to run any file. Multiple files can be open at the same time and switching between them is easily accomplished by the tabs at the top. Crimson Editor also will allow you to organize the files you choose into projects. There are many more useful features, but I will let you check them out for yourself. Just search the internet for Crimson Editor.

Creating our Sample Application

Create a new directory named WebApp1. If your using IIS create a new virtual directory named WebApp1 that points to this directory and on the ASP.NET tab select version 2.0.

If you are using Crimson Editor create a new project named WebApp1 by selecting New Project from the Project menu. Save this file named WebApp1.prj in the directory you created (Optional).

Using your text editor, create a new text file, copy Listing 1 into it and save the file as Default.aspx.

Listing 1 - Default.aspx

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Home Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>Home Page Content (Default.aspx).</p>
</asp:Content>

Using your text editor, create a new text file, copy Listing 2 into it and save the file as Web.config.

Listing 2 - Web.config

<?xml version="1.0"?>
<configuration>
      <appSettings/>
      <connectionStrings/>
      <system.web>
            <compilation debug="true" strict="false" explicit="true"/>
      </system.web>
</configuration>

Using your text editor, create a new text file, copy Listing 3 into it and save the file as Default.aspx.

Listing 3 - MasterPage.master

<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Your Web Site</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>Master Page Content.</p>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
    </div>
    </form>
</body>
</html>

If you are using Crimson Editor and have these 3 files still open, you can click the Add All Open Files to Project button and then all 3 files should now be visible in the Project view. With Crimson Editor you can add and remove files from the project at anytime using the Project view.

Compiling Our Sample Application

Now that we have created our application the next step is to compile it. I will cover two ways to pre-compile your web application in place using the ASP.NET command line compiler aspnet_compiler.exe. The first is to use a batch file. And the second makes use of Crimson Editor's ability to execute external programs with arguments. Listing 4 shows what the pre-compile batch file looks like.

Listing 4 - Make.bat used to pre-compile our web application

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /WebApp1
pause

To set this up in CrimsonEditor, select Conf. User Tools from the Tools menu. And in the Preferences dialog box fill in the fields for the first User Tool using the following and also take a look at Image 1 below.

Menu Text: Compile ASP.NET - WebApp1

Command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe

Argument: -v /WebApp1

Initial Dir:

Hot Key: None

Close on exit: yes

Capture Output: yes

Use short file names: no

Save before execute: yes

Figure 1 - Setting up a User Tool to execute the ASP.NET compiler in Crimson Editor

If you are using the batch file method, just double click on it to run it. A command window will open and show the compiler output. If there are no errors displayed, you have successfully pre-compiled your web application.

With Crimson Editor you can select the User Tool we created from the Tools menu or use the Ctrl+1 shortcut. When activating this command,an output window will appear inside Crimson Editor instead of a command window. If no errors are shown the final output should read: "Terminated with exit code 0." This means that the application successfully pre-compiled.

A batch file can also be used within Crimson Editor, just right click on the file and select the Shell Execute command from the popup menu.

Launching Our Sample Application in a Web Browser

Now that we have compiled our web application, why wait any longer. Let us launch it in a browser and see how it looks. Again, we have the choice of creating a batch file or setting up a User Tool in Crimson Editor. The batch file to launch our web application is shown in Listing 5.

Listing 5 - Launch.bat used to display our web application in Internet Explorer

START IEXPLORE.EXE http://localhost/WebApp1

To set this up in Crimson Edito, select Conf. User Tools from the Tools menu. In the Preferences dialog box, fill in the fields for the second User Tool using the following and also take a look at Image 2 below.

Menu Text: View in browser - Web App Name

Command: C:\Program Files\Internet Explorer\iexplore.exe

Argument: http://localhost/webappname

Initial Dir:

Hot Key: None

Close on exit: yes

Capture Output: no

Use short file names: no

Save before execute: no

Figure 2 - Setting up a User Tool to launch a web application within a web browser in Crimson Editor

Deploying Our Sample Application

Once we have seen our web application in action all that is left is to deploy it to a test server or straight to the live server. Once again we have the choice of creating a batch file or setting up a User Tool in Crimson Editor. The batch file to deploy our web application is shown in Listing 6. As you can see, we will accomplish this using the xcopy command.

Listing 6 - Deploy.bat used to deploy our web application

xcopy /i /s /y /exclude:Excludes.txt C:\Projects\WebApp1 C:\Projects\WebApp1_Deploy 
 pause

Here is an explanation of the parameters used with xcopy. Using the /y parameter saves time, but you can decide how you use it. The source and destination directory need to use the physical path.

/s : Copies directories and subdirectories, unless they are empty.

/i : If a directory in destination does not exist, xcopy creates a new directory.

/exclude:Excludes.txt : Specifies a file containing a list of file extensions to exclude.

/y : Suppresses prompting to confirm that you want to overwrite an existing destination file.

To set this up in Crimson Editor, select Conf. User Tools from the Tools menu. And in the Preferences dialog box, fill in the fields for the third User Tool using the following and also take a look at Image 3 below.

Menu Text: Deploy - WebApp1

Command: C:\Windows\system32\xcopy.exe

Argument: /I /s /y /exclude:Excludes.txt C:\Projects\WebApp1 C:\Projects\WebApp1_Deploy

Initial Dir:

Hot Key: None

Close on exit: yes

Capture Output: no

Use short file names: no

Save before execute: no

Figure 3 - Setting up a User Tool to deploy a web in Crimson Editor

 

Listing 7 - Excludes.txt

.bat
.prj
.txt

Conclusion

Hopefully, this walk through has demonstrated how easy it is to develop web applications with a text editor. This was a simple application, but you can accomplish much more using this method, including Windows/Console applications. So remember, we can still enjoy developing web applications with a text editor.



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 2:04:16 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search