Pronunciation / adjective
Bringing something good and unforseen.
    Skip Navigation Links > Component Library > Page Utilities Object
   

The Fortunate.PageUtilities object - create and check connectivity to urls. It may be used for both windows development and web development.



 

Fortunate.PageUtilities

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:
  1. <appSettings>
  2. <!--Valid Environment Values: Development, Localhost, Production, Staging-->
  3. <add key="ApplicationEnvironment" value="Development"/>
  4. </appSettings>


I like to make the application object available to an entire web application by declaring it in the master page of a website.
  1. Private _ApplicationObject As Fortunate.Application
  2. Public ReadOnly Property ApplicationObject() As Fortunate.Application
  3. Get
  4. Call InitializeApplicationObject()
  5. Return _ApplicationObject
  6. End Get
  7. End Property
  8. Private Sub InitializeApplicationObject()
  9. If _ApplicationObject Is Nothing Then
  10. Me._ApplicationObject = New Fortunate.Application
  11. '
  12. 'AboutFortunateApplicationObject
  13. '
  14. Me._ApplicationObject.ApplicationName = "About Fortunate Website"
  15. Me._ApplicationObject.ApplicationType = Fortunate.Application.ApplicationTypes.Internet
  16. Me._ApplicationObject.BaseFilePathDevelopment = ""
  17. Me._ApplicationObject.BaseFilePathLocalhost = "C:\Users\Philosopher\Documents\Visual Studio 2005\Projects\AboutFortunate\AboutFortunateWeb"
  18. Me._ApplicationObject.BaseFilePathProduction = ""
  19. Me._ApplicationObject.BaseFilePathStaging = ""
  20. Me._ApplicationObject.BaseUriDevelopment = "http://development.aboutfortunate.com"
  21. Me._ApplicationObject.BaseUriLocalHost = "http://localhost/AboutFortunateWeb"
  22. Me._ApplicationObject.BaseUriProduction = "http://www.aboutfortunate.com"
  23. Me._ApplicationObject.BaseUriStaging = "http://staging.aboutfortunate.com"
  24. End If
  25. End Sub


To access the application object from a sub page the Master page needs to be typed. (Note the second line of code.)
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" EnableSessionState="True" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Default" %>
  2. <%@ 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:
  1. Dim PageUtilitiesObject As New Fortunate.PageUtilities(Master.ApplicationObject)
  2. 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:
  1. Dim PageUtilitiesObject As New Fortunate.PageUtilities(Master.ApplicationObject)
  2. 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.
Microsoft Certified Professional   © 2017 Fortunate.  All rights reserved.
contact: justin@aboutfortunate.com