Saturday, January 26, 2013

Wow! Where am i?

Do you every feel lost and just wish you could ping the cave walls like a bat? I found a way to sniff the url line yesterday. Awake last night, I realized that if you split a url on the slash and take the third item in the collection that you will have your hands on the subdomain standalone.

public static string GetSecureSubDomainWithoutTrailingSlash()
{
   string fullUrl = HttpContext.Current.Request.Url.ToString();
   return "https://" + fullUrl.Split('/')[2];
}

 
 

This posting may serve as a companion piece for this which shows off how to find where one is at in a file structure. Also, here is the VB Script way to do the thing I did above in C#:

Imports Microsoft.VisualBasic
Public Class LocationProvider
      Public Shared Function GetSecureSubDomainWithoutTrailingSlash() As String
            Dim fullUrl As String = HttpContext.Current.Request.Url.ToString()
            Dim revisedUrl As String = "https://" + Split(fullUrl, "/")(2)
            Return revisedUrl
      End Function
End Class

 
 

Call things static-style in VB script like so:

Label1.Text = LocationProvider.GetSecureSubDomainWithoutTrailingSlash()

No comments:

Post a Comment