Solved

Getting the base URL of an application

Posted on 2009-06-27
4
330 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
Call a VB.net function in Javascript 6 51
Read top line from CSV file 14 58
async questions 5 48
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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