What is my website name

J

Juan T. Llibre

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim fullpathandport as string = "The full URL and port for the application root is : " & "http://" & fullappname & ":" &
port & Request.ApplicationPath & "/"

See a working example at : http://asp.net.do/test/apppath.aspx
( the last line returns the info you want ... )
 
M

Mark Rae [MVP]

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim fullpathandport as string = "The full URL and port for the application
root is : " & "http://" & fullappname & ":" & port &
Request.ApplicationPath & "/"

What if it's https...?
 
J

Juan T. Llibre

I don't have a server certificate handy to test this, but this should cover that :

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim MyUrl As Uri = Request.Url
Dim fullappnameProtocolAndPort As String = "The full URL, protocol and port for the application root is : " _
& Server.HtmlEncode(MyUrl.Scheme) & "://" & fullappname & ":" & port & Request.ApplicationPath & "/"
 
M

Mark Rae [MVP]

I don't have a server certificate handy to test this, but this should cover
that :

I normally use something like this:

string strWebRoot = (Request.ServerVariables["HTTPS"] == "off" ? "http://" :
"https://") + Request.ServerVariables["SERVER_NAME"];
 
G

Guest

You get portnumber, protocol
page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
"/" + page.Request.Url.Segments(1)
--
Arne Garvander
Certified Geek
Professional Data Dude
 
J

Juan T. Llibre

Request.ServerVariables["SERVER_NAME"]; and Request.Url.Host return the same object, right ?

You're missing the application's name and the port, per the OP's request, though.

There's many ways to skin a cat.

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim prot as object = IIf(Request.ServerVariables("HTTPS")="on", "https://", "http://")
Dim path as String = prot.ToString() & fullappname & ":" & port & Request.ApplicationPath

....will also do the job.

:)





I normally use something like this:
string strWebRoot = (Request.ServerVariables["HTTPS"] == "off" ? "http://" : "https://") +
Request.ServerVariables["SERVER_NAME"];
 
M

Mark Rae [MVP]

Request.ServerVariables["SERVER_NAME"]; and Request.Url.Host return the
same object, right ?

Yes - AFAIK, Request.Url is just a wrapper around Request.ServerVariables...
You're missing the application's name and the port, per the OP's request,
though.

Probably... :)
There's many ways to skin a cat.

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim prot as object = IIf(Request.ServerVariables("HTTPS")="on",
"https://", "http://")
Dim path as String = prot.ToString() & fullappname & ":" & port &
Request.ApplicationPath

...will also do the job.

Indeed.
 
J

Juan T. Llibre

That's very compact, Arne.

That only leaves the port to be added :

Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim fullpath as string = page.Request.Url.Scheme + "://" + page.Request.Url.Authority + ":" + port + "/" +
page.Request.Url.Segments(1)
 
J

Juan T. Llibre

re:
!> page.request.uri

That does *not* produce what the OP requested.

The OP wants to :

1. include the port number
2. *not* include the page's name

Please review this thread. The answer has already been provided in it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top