Saturday, March 31, 2012

What is my website name

I am looking for a property in the page object that would return something like
"http://localhost:1530/myapp"
What property should I look for?

--
Arne Garvander
Certified Geek
Professional Data DudeOn Aug 2, 11:12 pm, Arne <A...@.discussions.microsoft.comwrote:

Quote:

Originally Posted by

I am looking for a property in the page object that would return something like
"http://localhost:1530/myapp"
What property should I look for?


Arne, you can use the Request.ServerVariables() method

http://www.4guysfromrolla.com/webtech/092298-3.shtml
"Arne" <Arne@.discussions.microsoft.comwrote in message
news:94C9C2BF-959D-4E36-8555-FC3D1259AA22@.microsoft.com...

Quote:

Originally Posted by

>I am looking for a property in the page object that would return something
>like
"http://localhost:1530/myapp"
What property should I look for?


Request.ServerVariables["HTTP_HOST"]

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
page.request.url works better
--
Arne Garvander
Certified Geek
Professional Data Dude

"Mark Rae [MVP]" wrote:

Quote:

Originally Posted by

"Arne" <Arne@.discussions.microsoft.comwrote in message
news:94C9C2BF-959D-4E36-8555-FC3D1259AA22@.microsoft.com...
>

Quote:

Originally Posted by

I am looking for a property in the page object that would return something
like
"http://localhost:1530/myapp"
What property should I look for?


>
Request.ServerVariables["HTTP_HOST"]
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>


No they don't work so well
The page.request.uri works better.
--
Arne Garvander
Certified Geek
Professional Data Dude

"Alexey Smirnov" wrote:

Quote:

Originally Posted by

On Aug 2, 11:12 pm, Arne <A...@.discussions.microsoft.comwrote:

Quote:

Originally Posted by

I am looking for a property in the page object that would return something like
"http://localhost:1530/myapp"
What property should I look for?


>
Arne, you can use the Request.ServerVariables() method
>
http://www.4guysfromrolla.com/webtech/092298-3.shtml
>
>


"Arne" <Arne@.discussions.microsoft.comwrote in message
news:6EAB5661-612F-49D6-BEBA-AE092365BD14@.microsoft.com...

Quote:

Originally Posted by

page.request.url works better


How exactly does it "work better"...?

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
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 espaol : http://asp.net.do/foros/
======================================
"Arne" <Arne@.discussions.microsoft.comwrote in message news:94C9C2BF-959D-4E36-8555-FC3D1259AA22@.microsoft.com...

Quote:

Originally Posted by

>I am looking for a property in the page object that would return something like
"http://localhost:1530/myapp"
What property should I look for?
>
--
Arne Garvander
Certified Geek
Professional Data Dude


"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:OYTlMAX1HHA.4496@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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...?

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
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 espaol : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message news:%23G2XEiZ1HHA.4428@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message news:OYTlMAX1HHA.4496@.TK2MSFTNGP02.phx.gbl...
>

Quote:

Originally Posted by

>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...?
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:OZX4ebc1HHA.4428@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>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"];

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
You get portnumber, protocol
page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
"/" + page.Request.Url.Segments(1)
--
Arne Garvander
Certified Geek
Professional Data Dude

"Mark Rae [MVP]" wrote:

Quote:

Originally Posted by

"Arne" <Arne@.discussions.microsoft.comwrote in message
news:6EAB5661-612F-49D6-BEBA-AE092365BD14@.microsoft.com...
>

Quote:

Originally Posted by

page.request.url works better


>
How exactly does it "work better"...?
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
>
>


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 espaol : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message news:e7vbBhc1HHA.5796@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message news:OZX4ebc1HHA.4428@.TK2MSFTNGP03.phx.gbl...
>

Quote:

Originally Posted by

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


Quote:

Originally Posted by

I normally use something like this:


Quote:

Originally Posted by

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


Quote:

Originally Posted by

--
Mark Rae
ASP.NET MVP
http://www.markrae.net


"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:eW84aAd1HHA.1164@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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


Yes - AFAIK, Request.Url is just a wrapper around Request.ServerVariables...

Quote:

Originally Posted by

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


Probably... :-)

Quote:

Originally Posted by

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.

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
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 espaol : http://asp.net.do/foros/
======================================
"Arne" <Arne@.discussions.microsoft.comwrote in message news:2D26E478-EB26-43E6-AA31-D7DD0118E099@.microsoft.com...

Quote:

Originally Posted by

You get portnumber, protocol
page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
"/" + page.Request.Url.Segments(1)
--
Arne Garvander
Certified Geek
Professional Data Dude
>
>
"Mark Rae [MVP]" wrote:
>

Quote:

Originally Posted by

>"Arne" <Arne@.discussions.microsoft.comwrote in message
>news:6EAB5661-612F-49D6-BEBA-AE092365BD14@.microsoft.com...
>>

Quote:

Originally Posted by

page.request.url works better


>>
>How exactly does it "work better"...?
>>
>>
>--
>Mark Rae
>ASP.NET MVP
>http://www.markrae.net
>>
>>


page.request.uri

--
<a href="http://links.10026.com/?link=http://1pakistangifts.com">Send Gifts to Pakisan at #Pakistan Gifts
Store</a| <a href="http://links.10026.com/?link=http://dotspecialists.com">Leading Software offshoring
and outsourcing service provider</a| <a
href="http://websitedesignersrus.com">Professional Websites at affordable
prices</a>
"Arne" <Arne@.discussions.microsoft.comwrote in message
news:94C9C2BF-959D-4E36-8555-FC3D1259AA22@.microsoft.com...

Quote:

Originally Posted by

>I am looking for a property in the page object that would return something
>like
"http://localhost:1530/myapp"
What property should I look for?
>
--
Arne Garvander
Certified Geek
Professional Data Dude
>


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 espaol : http://asp.net.do/foros/
======================================
"Enigma Boy" <enigma777@.pp.newsgroups.userwrote in message news:CTzti.3393$9W6.2439@.fe103.usenetserver.com...

Quote:

Originally Posted by

page.request.uri
>
--
<a href="http://links.10026.com/?link=http://1pakistangifts.com">Send Gifts to Pakisan at #Pakistan Gifts Store</a| <a
href="http://dotspecialists.com">Leading Software offshoring and outsourcing service provider</a| <a
href="http://websitedesignersrus.com">Professional Websites at affordable prices</a>
"Arne" <Arne@.discussions.microsoft.comwrote in message news:94C9C2BF-959D-4E36-8555-FC3D1259AA22@.microsoft.com...

Quote:

Originally Posted by

>>I am looking for a property in the page object that would return something like
>"http://localhost:1530/myapp"
>What property should I look for?
>>
>--
>Arne Garvander
>Certified Geek
>Professional Data Dude
>>


>
>
>

0 comments:

Post a Comment