Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the base URL of an application

Posted on 2009-06-27
4
Medium Priority
?
345 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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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