Here is my messy function I created in urlrewritemodule.vb that works for me but may not be the prettiest. I basically give names to search for and corresponding tabs to direct to. So if the first word after the portal alias matches one of my terms, I redirect to the tabname designated for that term. With that in mind, I can have restaurants, bars, night-clubs, all redirect to my "mycity" tab.
Private Function checkYAPTabPath(ByVal tabpath As String, ByVal yapToken As String, ByVal directedTab As String) As String tabpath = tabpath.Replace("//", "/")
Dim locSplit As String() locSplit = tabpath.Split("/".ToCharArray) If locSplit.Length > 2 Then tabpath = "//" & locSplit(1) & "//" & locSplit(locSplit.Length - 1) tabpath = tabpath.Substring(0, tabpath.LastIndexOf("//")).Replace("//" & yapToken, "") & "//" & directedTab Else tabpath = "//" & locSplit(1) End If Return tabpath End Function
and here is corresponding function calls in IdentifyByTabPath():
Private Function IdentifyByTabPath(ByVal app As HttpApplication) As Boolean
Dim domain As String = "" Dim url As String = app.Request.Url.ToString()
If (url.ToLower().StartsWith("http://")) Then url = url.Replace("http://", "") End If
' Remove QueryString if it exists If (app.Request.Url.Query <> "") Then url = url.Replace(app.Request.Url.Query, "") End If
Dim splitUrl() As String = url.Split(Convert.ToChar("/"))
Dim myAlias As String = "" If (splitUrl.Length > 0) Then For Each urlPart As String In splitUrl
If (myAlias = "") Then myAlias = urlPart Else myAlias = myAlias & "/" & urlPart End If
Dim objPortalAlias As PortalAliasInfo = PortalSettings.GetPortalAliasInfo(myAlias) If Not objPortalAlias Is Nothing Then Dim portalID As Integer = objPortalAlias.PortalID
' Identify Tab Name
Dim tabPath As String = url.Replace(myAlias, "").ToLower()
' Default Page has been Requested If (tabPath = "/" & glbDefaultPage.ToLower()) Then Return True End If
If (tabPath = "/login.aspx") Then RewriterUtils.RewriteUrl(app.Context, "~/" & glbDefaultPage & "?portalid=" & portalID.ToString() & "&ctl=login") Return True End If
If (tabPath = "/register.aspx") Then RewriterUtils.RewriteUrl(app.Context, "~/" & glbDefaultPage & "?portalid=" & portalID.ToString() & "&ctl=Register") Return True End If
If (tabPath = "/terms.aspx") Then RewriterUtils.RewriteUrl(app.Context, "~/" & glbDefaultPage & "?portalid=" & portalID.ToString() & "&ctl=Terms") Return True End If
If (tabPath = "/privacy.aspx") Then RewriterUtils.RewriteUrl(app.Context, "~/" & glbDefaultPage & "?portalid=" & portalID.ToString() & "&ctl=Privacy") Return True End If
tabPath = tabPath.Replace("/", "//") tabPath = tabPath.Replace(".aspx", "")
tabPath = Me.checkYAPTabPath(tabPath, "locations", "mycity") tabPath = Me.checkYAPTabPath(tabPath, "restaurants", "mycity") tabPath = Me.checkYAPTabPath(tabPath, "clubs", "mycity") tabPath = Me.checkYAPTabPath(tabPath, "bars", "mycity")
|