Download the Fortunate Library Here:
Fortunate Library 32bit - Stand-Alone Install
Fortunate Library 64bit - Stand-Alone Install
Fortunate Library Solution - Source Code
The Fortunate.PageUtilties object may be used to check if a uri is available before attempting to work with it. It may also be used to create site uris which are correct for the current deployment environment via the Fortunate.Application object's base uri settings and environment.
The Fortunate.PageUtilities object takes the Fortunate.Application object as a parameter. The following code shows how I like to declare the Application object for use in any page.
The Fortunate.Application environment may be set in a web.config or app.config file:
<appSettings>
<!--Valid Environment Values: Development, Localhost, Production, Staging-->
<add key="ApplicationEnvironment" value="Development"/>
</appSettings>
I like to make the application object available to an entire web application by declaring it in the master page of a website.
Private _ApplicationObject As Fortunate.Application
Public ReadOnly Property ApplicationObject() As Fortunate.Application
Get
Call InitializeApplicationObject()
Return _ApplicationObject
End Get
End Property
Private Sub InitializeApplicationObject()
If _ApplicationObject Is Nothing Then
Me._ApplicationObject = New Fortunate.Application
'
'AboutFortunateApplicationObject
'
Me._ApplicationObject.ApplicationName = "About Fortunate Website"
Me._ApplicationObject.ApplicationType = Fortunate.Application.ApplicationTypes.Internet
Me._ApplicationObject.BaseFilePathDevelopment = ""
Me._ApplicationObject.BaseFilePathLocalhost = "C:\Users\Philosopher\Documents\Visual Studio 2005\Projects\AboutFortunate\AboutFortunateWeb"
Me._ApplicationObject.BaseFilePathProduction = ""
Me._ApplicationObject.BaseFilePathStaging = ""
Me._ApplicationObject.BaseUriDevelopment = "http://development.aboutfortunate.com"
Me._ApplicationObject.BaseUriLocalHost = "http://localhost/AboutFortunateWeb"
Me._ApplicationObject.BaseUriProduction = "http://www.aboutfortunate.com"
Me._ApplicationObject.BaseUriStaging = "http://staging.aboutfortunate.com"
End If
End Sub
To access the application object from a sub page the Master page needs to be typed. (Note the second line of code.)
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" EnableSessionState="True" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Default" %>
<%@ MasterType VirtualPath="~/masterPage.master" %>
The page utilities object may now be used in two different ways.
It may be used to check any uri's availability:
Dim PageUtilitiesObject As New Fortunate.PageUtilities(Master.ApplicationObject)
Dim UriAvailable As Boolean = PageUtilitiesObject.CheckUriStatus("www.uritocheck.com", [Optional Authorization As System.NetCredentialCache], [Optional Return Error As Boolean])
And it may be used to create uris based on the values placed into the application object's base uri properties:
Dim PageUtilitiesObject As New Fortunate.PageUtilities(Master.ApplicationObject)
Dim Uri As Uri = PageUtilitiesObject.Uri("/terms.htm")
When the environment is set to localhost the uri returned is: http://localhost/AboutFortunateWeb/terms.htm
And when the environment is set to production the uri returned is: http://wwwaboutfortunate.com/terms.htm
While the same functionality can often be achieved using the tilde (~) character, forming a uri with the tilde is not possible in all situations. The Fortunate.PageUtilities object is intended to be used in just such a situation.
|