Solved

Getting the base URL of an application

Posted on 2009-06-27
4
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 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