Click here to Skip to main content
15,886,068 members
Articles / Web Development / ASP.NET

Switching Between HTTP and HTTPS Automatically: Version 2

Rate me:
Please Sign up or sign in to vote.
4.91/5 (223 votes)
7 Feb 2011CPOL18 min read 3.5M   680  
An article on automatically switching between HTTP and HTTPS protocols without hard-coding absolute URLs
Namespace Ventaur.Web.Security.Configuration

	''' <summary>
	''' The SecureWebPageDirectory class represents a directory entry in the &lt;secureWebPages&gt;
	''' configuration section.
	''' </summary>
	Public Class SecureWebPageDirectory
		Inherits SecureWebPageItem

		' Fields
		Private _recurse As Boolean = False

		''' <summary>
		''' Gets or sets a flag indicating whether or not to include all files in any sub-directories 
		''' when evaluating a request.
		''' </summary>
		Public Property Recurse() As Boolean
			Get
				Return _recurse
			End Get
			Set(ByVal Value As Boolean)
				_recurse = Value
			End Set
		End Property

		''' <summary>
		''' Creates an instance with default values.
		''' </summary>
		Public Sub New()
			MyBase.New()
		End Sub

		''' <summary>
		''' Creates an instance with initial values.
		''' </summary>
		''' <param name="path">The relative path to the directory or file.</param>
		''' <param name="ignore">A flag to ignore security for the directory or file.</param>
		Public Sub New(ByVal path As String, ByVal secure As SecurityType, ByVal recurse As Boolean)
			MyBase.New(path, secure)
			Me._recurse = recurse
		End Sub

		''' <summary>
		''' Creates an instance with an initial path value.
		''' </summary>
		''' <param name="path">The relative path to the directory or file.</param>
		Public Sub New(ByVal path As String)
			MyBase.New(path)
		End Sub

	End Class

	''' <summary>
	''' The SecureWebPageDirectoryCollection class houses a collection of SecureWebPageDirectory instances.
	''' </summary>
	Public Class SecureWebPageDirectoryCollection
		Inherits SecureWebPageItemCollection

		''' <summary>
		''' Initialize an instance of this collection.
		''' </summary>
		Public Sub New()
			MyBase.New()
		End Sub

		''' <summary>
		''' Indexer for the collection.
		''' </summary>
		Default Public ReadOnly Property Item(ByVal index As Integer) As SecureWebPageDirectory
			Get
				Return CType(List(index), SecureWebPageDirectory)
			End Get
		End Property

		''' <summary>
		''' Adds the item to the collection.
		''' </summary>
		''' <param name="item">The item to add.</param>
		Public Function Add(ByVal item As SecureWebPageDirectory) As Integer
			Return List.Add(item)
		End Function

		''' <summary>
		''' Inserts an item into the collection at the specified index.
		''' </summary>
		''' <param name="index">The index to insert the item at.</param>
		''' <param name="item">The item to insert.</param>
		Public Sub Insert(ByVal index As Integer, ByVal item As SecureWebPageDirectory)
			List.Insert(index, item)
		End Sub

		''' <summary>
		''' Removes an item from the collection.
		''' </summary>
		''' <param name="item">The item to remove.</param>
		Public Sub Remove(ByVal item As SecureWebPageDirectory)
			List.Remove(item)
		End Sub

	End Class

End Namespace

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.

The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).

Comments and Discussions