Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

What is my website name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne - 02 Aug 2007 22:12 GMT
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?

Signature

Arne Garvander
Certified Geek
Professional Data Dude

Alexey Smirnov - 02 Aug 2007 22:27 GMT
> 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 - 02 Aug 2007 22:46 GMT
No they don't work so well
The page.request.uri works better.
Signature

Arne Garvander
Certified Geek
Professional Data Dude

> > I am looking for a property in the page object that would return something like
> > "http://localhost:1530/myapp"
[quoted text clipped - 3 lines]
>
> http://www.4guysfromrolla.com/webtech/092298-3.shtml
Mark Rae [MVP] - 02 Aug 2007 22:29 GMT
>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"]

Signature

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

Arne - 02 Aug 2007 22:46 GMT
page.request.url works better
Signature

Arne Garvander
Certified Geek
Professional Data Dude

> >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 [MVP] - 02 Aug 2007 23:09 GMT
> page.request.url works better

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

Signature

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

Arne - 03 Aug 2007 14:04 GMT
You get portnumber, protocol
page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
          "/" + page.Request.Url.Segments(1)
Signature

Arne Garvander
Certified Geek
Professional Data Dude

> > page.request.url works better
>
> How exactly does it "work better"...?
Juan T. Llibre - 03 Aug 2007 14:56 GMT
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/
======================================
> You get portnumber, protocol
> page.Request.Url.Scheme + "://" + page.Request.Url.Authority + _
[quoted text clipped - 3 lines]
>>
>> How exactly does it "work better"...?
Juan T. Llibre - 03 Aug 2007 02:45 GMT
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/
======================================
>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?
Mark Rae [MVP] - 03 Aug 2007 07:35 GMT
> 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...?

Signature

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

Juan T. Llibre - 03 Aug 2007 13:07 GMT
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/
======================================

>> 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 [MVP] - 03 Aug 2007 13:17 GMT
>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"];

Signature

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

Juan T. Llibre - 03 Aug 2007 14:13 GMT
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 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 [MVP] - 03 Aug 2007 14:28 GMT
> 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.
>
[quoted text clipped - 6 lines]
>
> ...will also do the job.

Indeed.

Signature

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

Enigma Boy - 06 Aug 2007 08:14 GMT
page.request.uri

Signature

<a href="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>

>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?
Juan T. Llibre - 06 Aug 2007 11:57 GMT
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/
======================================
> page.request.uri
>
>>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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.