What is my website name

  • Thread starter Thread starter Guest
  • Start date Start date
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 ... )




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
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...?
 
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 & "/"




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
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"];
 
You get portnumber, protocol
page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
"/" + page.Request.Url.Segments(1)
--
Arne Garvander
Certified Geek
Professional Data Dude
 
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.

:-)




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
I normally use something like this:
string strWebRoot = (Request.ServerVariables["HTTPS"] == "off" ? "http://" : "https://") +
Request.ServerVariables["SERVER_NAME"];
 
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.
 
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)





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
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.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Back
Top