Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version
Go to top

A Simple protocol to view aspx pages without IIS implemented in C#

, 17 Feb 2004
Covers how to write a Pluggable Asyncrhonous Protocol using C# and provides a useful protocol to enable local execution of ASP.NET sites.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace Protocol
	/// <summary>
	/// Summary description for EchoProtocol.
	/// </summary>
	[ Guid("E00957BD-D0E1-4eb9-A025-7743FDC8B27B"), ComVisible(true), ClassInterface(ClassInterfaceType.None)]
	[ AsyncProtocol(Name="echo", Description="Returns the URL of the protocol as HTML content.") ]
	public class EchoProtocol : ProtocolBase, IInternetProtocol, IInternetProtocolRoot
		#region IInternetProtocol Members

		public void Start(string szURL, IInternetProtocolSink Sink, IInternetBindInfo pOIBindInfo, uint grfPI, uint dwReserved)
			Debug.WriteLine("Start:" + szURL, "Info");
				if (Sink is IServiceProvider)
					IServiceProvider Provider = (IServiceProvider)Sink;
					object obj_Negotiate = new object();
					Provider.QueryService(ref Guids.IID_IHttpNegotiate, ref Guids.IID_IHttpNegotiate, out obj_Negotiate);
					IHttpNegotiate Negotiate = (IHttpNegotiate)obj_Negotiate;

					string strNewHeaders;
					Negotiate.BeginningTransaction(szURL, string.Empty, 0, out strNewHeaders);

					StreamWriter Writer = new StreamWriter(Stream); 
					int loc = szURL.IndexOf(':');
					if (loc >= 0)
						Writer.Write(string.Format("<HTML><BODY>{0}</BODY></HTML>", System.Web.HttpUtility.UrlDecode(szURL.Remove(0, loc+1))));
						Writer.Write(string.Format("<HTML><BODY>{0}</BODY></HTML>", System.Web.HttpUtility.UrlDecode(szURL)));
					Stream.Position = 0;

					string StrResponseHeaders = string.Format("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length:{0}\r\n\r\n", Stream.Length);
					string strNewResponseHeaders;
					Negotiate.OnResponse(200, StrResponseHeaders, strNewHeaders, out strNewResponseHeaders);

				Sink.ReportData(BSCF.BSCF_LASTDATANOTIFICATION, (uint)Stream.Length, (uint)Stream.Length);
				Sink.ReportResult(0, 200, null);
			catch (Exception e)


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Andy Brummer
Architect Michael & Susan Dell Foundation
United States United States
I'm a web developer, math and physics enthusiast, and all around great guy. I live in Austin TX and love using technology to change people's lives for the better.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 18 Feb 2004
Article Copyright 2004 by Andy Brummer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid