Solved

Getting the base URL of an application

Posted on 2009-06-27
4
320 Views
Last Modified: 2012-08-14
Hello

How do I get the domain name of which my application runs on? For example, in my application test environment, visual studio 2008 gives me a random url, such as:

http://localhost:1141/[MY_SITE_NAME]/Default.aspx

I want this portion of the url: http://localhost:1141
0
Comment
Question by:alfardan
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Espavo
ID: 24728920
I do it like this:
Dim HTTP_HOST As String = Request.Url.GetLeftPart(UriPartial.Authority) & Page.ResolveUrl("~/")
0
 
LVL 16

Accepted Solution

by:
MikeMCSD earned 500 total points
ID: 24728942
I think this one:

      Session("absURL") = Request.Url.AbsoluteUri



0
 

Author Comment

by:alfardan
ID: 24729105
Espavo
I think your code is the one I'm looking for, howeverm if I do place this code in an aspx.vb file then i works fine, however, if I place it in a class that is located in the App_Code folder (as per Visual Studio 2005+ requirement) then it gives me an error for using the (Page.ResolveUrl("~/")) , it says: Reference to a non-shared member requires an object reference.
What's that mean?
All I did is that I placed your code in a function that is in my class that is located in App)Code folder. See the declaration of this function in the code section of this post.

Public Function GetMyDomain() As String
 

Return Current.Request.Url.GetLeftPart(UriPartial.Authority) & Page.ResolveUrl("~/")
 

End Function

Open in new window

0
 

Author Closing Comment

by:alfardan
ID: 31597588
I used your code, but it didn't give me exactly what I wanted, but it helped me in getting what I wanted. This is the solution I needed exactly:

Public Function GetMyDomainLink() As String

        Dim DomainLink As String = Current.Request.Url.AbsoluteUri
        Dim Spliter() As String = Split(DomainLink, "://")
        DomainLink = Mid(Spliter(1), 1, Spliter(1).IndexOf("/"))
        DomainLink = Spliter(0) + "://" + DomainLink


        Return DomainLink

    End Function
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now