Click here to Skip to main content
11,496,146 members (603 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

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

, 17 Feb 2004 295.9K 5.9K 149
Covers how to write a Pluggable Asyncrhonous Protocol using C# and provides a useful protocol to enable local execution of ASP.NET sites.
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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");
			try 
			{
				if (Sink is IServiceProvider)
				{
					Debug.WriteLine("ServiceProvider");
					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);
					Debug.WriteLine(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))));
					else
						Writer.Write(string.Format("<HTML><BODY>{0}</BODY></HTML>", System.Web.HttpUtility.UrlDecode(szURL)));
					Writer.Flush();
					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);
					Debug.WriteLine(strNewResponseHeaders);
				}

				Sink.ReportData(BSCF.BSCF_LASTDATANOTIFICATION, (uint)Stream.Length, (uint)Stream.Length);
				Sink.ReportResult(0, 200, null);
			} 
			catch (Exception e)
			{
				Debug.WriteLine(e.Message);
			}
		}

		#endregion
	}
}

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.

License

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

Share

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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 18 Feb 2004
Article Copyright 2004 by Andy Brummer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid