Aspx Hosting Sample

 

This document contains the release information for the .NET Framework Aspx Hosting sample. You will find the following sections below:

 

Overview.. 1

Building the Sample. 1

Running the Sample. 1

Notes. 1

Features of HttpListener used. 1

Class Description. 1

Sample Usage. 2

Setting Authentication Scheme. 2

Enabling Ssl 2

Further Reading. 2

FAQ.. 2

 

 

Overview

 

Microsoft .Net 1.1 shipped API’s that can be used to host Aspx applications without IIS. Then the beta1 version on .Net 2.0 shipped HttpListener class built on top of Http.Sys that enabled users to create a stand alone Http Server. This demo illustrates how to combine the features of HttpListener to create an Http serer that in turn routes calls to the hosted Aspx application.

 

Building the Sample

In order to properly build and run this sample, the following steps need to be performed.

Open the project file AspxHostCS.sln using Visual Studio 2005 Beta

Then build the project by clicking Build-> Build  Project.

Running the Sample

In order to run this sample, follow one of the instructions listed below.

  • Run the project from Visual Studio 2005 Beta
  • Open a command prompt and go to the location of the sample. Change to bin\Debug directory from that location. Execute AspxHostCS.exe application.

Before running the sample, refer to Notes->Sample Usage section.

Notes

Features of HttpListener used

 

  1. Authentication
  2. Enabling Ssl
  3. Reading Client Certificates on secure connections

 

Class Description

 

AspxHostCS.cs è The main class that creates and configures a listener and an Aspx application.

AspxVirtualRoot.cs è Class that configures an HttpListener to listen on prefixes and authentication schemes supported.

AspxNetEngine.cs è Class that configures an Aspx application by assigning a virtual alias that maps to a physical directory.

AspxPage.cs è Class that implements SimpleWorkerRequest class and represents a page requested by the client.

AspxRequestInfo.cs è Data holder class that is used to pass relevant data from HttpListenerContext to the hosted app.

AspxException.cs è Custom exception class.

DemoPages èDirectory that contains sample Aspx pages

 

Sample Usage

 

AspxHostCS.cs file is the class that contains the main method that will launch an HttpListener and configure a physical directory as a hosted Aspx application. By default, the class tries to configure the DemoPages directory (Found in the same samples directory) as a hosted application under virtual alias /. If unchanged, on clicking the provided link will serve this Readme page.  Since the HttpListener in this sample listens on port 80 you may need to stop IIS to run this sample.

 

Change the code to make changes suited to individual use.

 

                //Create a AspxVirtualRoot object with a http port and https port if required

                AspxVirtualRoot virtualRoot = new AspxVirtualRoot(80);

 

                //Configure a Physical directory as a virtual alias.

                //TODO: Replace the physical directory with the directory to be configured.

                virtualRoot.Configure("/", Path.GetFullPath(@"..\..\DemoPages"));

 

                //TODO: If Authentication is to be added, add it here

                //virtualRoot.AuthenticationSchemes = AuthenticationSchemes.Basic;

 

Setting Authentication Scheme

 

After configuring an AspxVirtualRoot object, set the required authentication scheme by setting AuthenticationScheme field on AspxVirtualRoot object.

 

 

Enabling Ssl

 

To enable Ssl, a Server certificate installed on the machine store must be configured on the port where Ssl is required. For more information on how to configure Server certificate on a port using Httpcfg.exe util, refer Httpcfg link.

 

Note: Winhttpcertcfg can also be used for configuring Server cert on a port, Refer Winhttpcertcfg link.

 

Further Reading

 

For HttpListener documentation refer Msdn link

For Aspx Hosting Api documentation refer Msdn link.

 

FAQ

 

When I start the application, I get the following error message

 

 System.IO.FileNotFoundException: Could not load file or assembly 'AspxHostCS, Version=1.0.1809.19805, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.File name: 'AspxHostCS, Version=1.0.1809.19805, Culture=neutral, PublicKeyToken=null'

 

Solution:

 

The AspxHostCs.exe file is not present in the bin directory of the physical directory being configured. Copy the AspxHostcs.exe file to the bin directory.