What is my website name

Discussion in 'ASP .Net' started by =?Utf-8?B?QXJuZQ==?=, Aug 2, 2007.

  1. 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
    =?Utf-8?B?QXJuZQ==?=, Aug 2, 2007
    #1
    1. Advertising

  2. On Aug 2, 11:12 pm, Arne <> wrote:
    > 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
    Alexey Smirnov, Aug 2, 2007
    #2
    1. Advertising

  3. "Arne" <> wrote in message
    news:...

    >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
    Mark Rae [MVP], Aug 2, 2007
    #3
  4. page.request.url works better
    --
    Arne Garvander
    Certified Geek
    Professional Data Dude


    "Mark Rae [MVP]" wrote:

    > "Arne" <> wrote in message
    > news:...
    >
    > >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
    >
    >
    =?Utf-8?B?QXJuZQ==?=, Aug 2, 2007
    #4
  5. No they don't work so well
    The page.request.uri works better.
    --
    Arne Garvander
    Certified Geek
    Professional Data Dude


    "Alexey Smirnov" wrote:

    > On Aug 2, 11:12 pm, Arne <> wrote:
    > > 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
    >
    >
    =?Utf-8?B?QXJuZQ==?=, Aug 2, 2007
    #5
  6. "Arne" <> wrote in message
    news:...

    > page.request.url works better


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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 2, 2007
    #6
  7. 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/
    ======================================
    "Arne" <> wrote in message news:...
    >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, Aug 3, 2007
    #7
  8. "Juan T. Llibre" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Aug 3, 2007
    #8
  9. 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/
    ======================================
    "Mark Rae [MVP]" <> wrote in message news:%...
    > "Juan T. Llibre" <> wrote in message news:...
    >
    >> 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, Aug 3, 2007
    #9
  10. "Juan T. Llibre" <> wrote in message
    news:...

    >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
    Mark Rae [MVP], Aug 3, 2007
    #10
  11. 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:

    > "Arne" <> wrote in message
    > news:...
    >
    > > page.request.url works better

    >
    > How exactly does it "work better"...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    =?Utf-8?B?QXJuZQ==?=, Aug 3, 2007
    #11
  12. 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/
    ======================================
    "Mark Rae [MVP]" <> wrote in message news:...
    > "Juan T. Llibre" <> wrote in message news:...
    >
    >>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
    Juan T. Llibre, Aug 3, 2007
    #12
  13. "Juan T. Llibre" <> wrote in message
    news:...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 3, 2007
    #13
  14. 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/
    ======================================
    "Arne" <> wrote in message news:...
    > 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:
    >
    >> "Arne" <> wrote in message
    >> news:...
    >>
    >> > page.request.url works better

    >>
    >> How exactly does it "work better"...?
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net
    >>
    >>
    Juan T. Llibre, Aug 3, 2007
    #14
  15. =?Utf-8?B?QXJuZQ==?=

    Enigma Boy Guest

    page.request.uri

    --
    <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>
    "Arne" <> wrote in message
    news:...
    >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
    >
    Enigma Boy, Aug 6, 2007
    #15
  16. 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/
    ======================================
    "Enigma Boy" <> wrote in message news:CTzti.3393$...
    > page.request.uri
    >
    > --
    > <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>
    > "Arne" <> wrote in message news:...
    >>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, Aug 6, 2007
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    796
    Roedy Green
    Jan 2, 2006
  2. A Leon
    Replies:
    4
    Views:
    461
    A Leon
    Mar 4, 2004
  3. ding feng
    Replies:
    2
    Views:
    2,774
    ding feng
    Jun 25, 2003
  4. Bobby Chamness
    Replies:
    2
    Views:
    2,371
    Joe Smith
    Apr 22, 2007
  5. Jack-2
    Replies:
    3
    Views:
    249
    Jack-2
    Dec 24, 2003
Loading...

Share This Page