Obtaining the Absolute URL of a page

Discussion in 'ASP .Net' started by Nathan Sokalski, Sep 8, 2008.

  1. I have a page in my site that I need the absolute url of. Is there a
    function in .NET to which you can pass a relative url or something such as
    "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    because at the moment I do not know what the domain name (or if there is the
    possibility of the site going in a subdirectory) where the site will
    eventually exist. Also, this will make it easier to test during development.
    I need the absolute url because it will be getting sent as part of an email.
    Thanks.

    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Sep 8, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    Kalpesh Guest

    Does Request.Url help?

    Kalpesh

    On Sep 8, 10:50 am, "Nathan Sokalski" <>
    wrote:
    > I have a page in my site that I need the absolute url of. Is there a
    > function in .NET to which you can pass a relative url or something such as
    > "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    > because at the moment I do not know what the domain name (or if there is the
    > possibility of the site going in a subdirectory) where the site will
    > eventually exist. Also, this will make it easier to test during development.
    > I need the absolute url because it will be getting sent as part of an email.
    > Thanks.
    >
    > Nathan Sokalski
    > ://www.nathansokalski.com/
     
    Kalpesh, Sep 8, 2008
    #2
    1. Advertising

  3. On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    wrote:
    > I have a page in my site that I need the absolute url of. Is there a
    > function in .NET to which you can pass a relative url or something such as
    > "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    > because at the moment I do not know what the domain name (or if there is the
    > possibility of the site going in a subdirectory) where the site will
    > eventually exist. Also, this will make it easier to test during development.
    > I need the absolute url because it will be getting sent as part of an email.
    > Thanks.
    >
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    You can get your current absolute URL by using
    Request.Url.AbsoluteUri. you will have to modify the part different
    from the current relative url to the one that you want to return.
     
    Ignacio Machin ( .NET/ C# MVP ), Sep 8, 2008
    #3
  4. No, I am looking for a function that will get me the absolute URL of a page
    other than the page I am currently on. I want to avoid the need to use
    string manipulation, which would be required with anything in the Request
    object. Any other ideas?

    "Kalpesh" <> wrote in message
    news:...
    Does Request.Url help?

    Kalpesh

    On Sep 8, 10:50 am, "Nathan Sokalski" <>
    wrote:
    > I have a page in my site that I need the absolute url of. Is there a
    > function in .NET to which you can pass a relative url or something such as
    > "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    > because at the moment I do not know what the domain name (or if there is
    > the
    > possibility of the site going in a subdirectory) where the site will
    > eventually exist. Also, this will make it easier to test during
    > development.
    > I need the absolute url because it will be getting sent as part of an
    > email.
    > Thanks.
    >
    > Nathan Sokalski
    > ://www.nathansokalski.com/
     
    Nathan Sokalski, Sep 8, 2008
    #4
  5. That is what I am currently doing, however, I think it would be nice to have
    a method that can get me the absolute url of another page. Does such a
    function exist, or will I need to write it myself? Thanks.

    "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    message
    news:...
    On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    wrote:
    > I have a page in my site that I need the absolute url of. Is there a
    > function in .NET to which you can pass a relative url or something such as
    > "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    > because at the moment I do not know what the domain name (or if there is
    > the
    > possibility of the site going in a subdirectory) where the site will
    > eventually exist. Also, this will make it easier to test during
    > development.
    > I need the absolute url because it will be getting sent as part of an
    > email.
    > Thanks.
    >
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    You can get your current absolute URL by using
    Request.Url.AbsoluteUri. you will have to modify the part different
    from the current relative url to the one that you want to return.
     
    Nathan Sokalski, Sep 8, 2008
    #5
  6. On Sep 8, 4:06 pm, "Nathan Sokalski" <>
    wrote:
    > That is what I am currently doing, however, I think it would be nice to have
    > a method that can get me the absolute url of another page. Does such a
    > function exist, or will I need to write it myself? Thanks.
    >
    > "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    > messagenews:..com...
    > On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    > wrote:
    >
    > > I have a page in my site that I need the absolute url of. Is there a
    > > function in .NET to which you can pass a relative url or something such as
    > > "~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    > > because at the moment I do not know what the domain name (or if there is
    > > the
    > > possibility of the site going in a subdirectory) where the site will
    > > eventually exist. Also, this will make it easier to test during
    > > development.
    > > I need the absolute url because it will be getting sent as part of an
    > > email.
    > > Thanks.

    >
    > > Nathan Sokalski
    > > ://www.nathansokalski.com/

    >
    > You can get your current absolute URL by using
    > Request.Url.AbsoluteUri. you will have to modify the part different
    > from the current relative url to the one that you want to return.


    Why don't you post your question in the ASPNET NG?
     
    Ignacio Machin ( .NET/ C# MVP ), Sep 8, 2008
    #6
  7. Nathan Sokalski

    Hillbilly Guest

    Try ResolveUrl("~/dir/filename.asp") which will append the root path of the
    domain to the virtual path regardless of where the page is requested and
    compiled.



    "Nathan Sokalski" <> wrote in message
    news:Oug$...
    >I have a page in my site that I need the absolute url of. Is there a
    >function in .NET to which you can pass a relative url or something such as
    >"~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    >because at the moment I do not know what the domain name (or if there is
    >the possibility of the site going in a subdirectory) where the site will
    >eventually exist. Also, this will make it easier to test during
    >development. I need the absolute url because it will be getting sent as
    >part of an email. Thanks.
    >
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Hillbilly, Sep 8, 2008
    #7
  8. I have tried that, but it only gives the path, the domain name and protocol
    are not included. For example, it would return something like
    /mydirectory/mypage.aspx when I am looking for
    http://www.mydomain.com/mydirectory/mypage.aspx. Any other ideas?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Hillbilly" <> wrote in message
    news:%...
    > Try ResolveUrl("~/dir/filename.asp") which will append the root path of
    > the domain to the virtual path regardless of where the page is requested
    > and compiled.
    >
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:Oug$...
    >>I have a page in my site that I need the absolute url of. Is there a
    >>function in .NET to which you can pass a relative url or something such as
    >>"~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    >>because at the moment I do not know what the domain name (or if there is
    >>the possibility of the site going in a subdirectory) where the site will
    >>eventually exist. Also, this will make it easier to test during
    >>development. I need the absolute url because it will be getting sent as
    >>part of an email. Thanks.
    >>
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
     
    Nathan Sokalski, Sep 8, 2008
    #8
  9. In case you didn't notice, I did post it to
    microsoft.public.dotnet.framework.aspnet.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    message
    news:...
    On Sep 8, 4:06 pm, "Nathan Sokalski" <>
    wrote:
    > That is what I am currently doing, however, I think it would be nice to
    > have
    > a method that can get me the absolute url of another page. Does such a
    > function exist, or will I need to write it myself? Thanks.
    >
    > "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    > messagenews:...
    > On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    > wrote:
    >
    > > I have a page in my site that I need the absolute url of. Is there a
    > > function in .NET to which you can pass a relative url or something such
    > > as
    > > "~/mydirectory/mypage.aspx" which will return an absolute url? I need
    > > this
    > > because at the moment I do not know what the domain name (or if there is
    > > the
    > > possibility of the site going in a subdirectory) where the site will
    > > eventually exist. Also, this will make it easier to test during
    > > development.
    > > I need the absolute url because it will be getting sent as part of an
    > > email.
    > > Thanks.

    >
    > > Nathan Sokalski
    > > ://www.nathansokalski.com/

    >
    > You can get your current absolute URL by using
    > Request.Url.AbsoluteUri. you will have to modify the part different
    > from the current relative url to the one that you want to return.


    Why don't you post your question in the ASPNET NG?
     
    Nathan Sokalski, Sep 8, 2008
    #9
  10. Nathan Sokalski

    rstrahl Guest

    I think what you want is ResolveClientUrl() which will generate a fully
    qualified URL instead of a relative URL.

    You should be able to create a relative URL (~/path/sompage.aspx) and pass
    that to ResolveClientUrl() and get the absolute path that way.

    +++ Rick ---


    "Nathan Sokalski" <> wrote in message
    news:...
    > That is what I am currently doing, however, I think it would be nice to
    > have a method that can get me the absolute url of another page. Does such
    > a function exist, or will I need to write it myself? Thanks.
    >
    > "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    > message
    > news:...
    > On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    > wrote:
    >> I have a page in my site that I need the absolute url of. Is there a
    >> function in .NET to which you can pass a relative url or something such
    >> as
    >> "~/mydirectory/mypage.aspx" which will return an absolute url? I need
    >> this
    >> because at the moment I do not know what the domain name (or if there is
    >> the
    >> possibility of the site going in a subdirectory) where the site will
    >> eventually exist. Also, this will make it easier to test during
    >> development.
    >> I need the absolute url because it will be getting sent as part of an
    >> email.
    >> Thanks.
    >>
    >> Nathan Sokalski
    >> ://www.nathansokalski.com/

    >
    > You can get your current absolute URL by using
    > Request.Url.AbsoluteUri. you will have to modify the part different
    > from the current relative url to the one that you want to return.
    >
    >
     
    rstrahl, Sep 9, 2008
    #10
  11. No, that still gives me something like "/mydirectory/mypage.aspx", but it
    does not include the "http://www.mydomain.com". I am using code like the
    following:

    ResolveClientUrl("~/mydirectory/mypage.aspx")

    This is what you meant, right? If you have any other ideas (or if you did
    mean something else) please let me know. Thanks.

    "rstrahl" <> wrote in message
    news:...
    >I think what you want is ResolveClientUrl() which will generate a fully
    >qualified URL instead of a relative URL.
    >
    > You should be able to create a relative URL (~/path/sompage.aspx) and pass
    > that to ResolveClientUrl() and get the absolute path that way.
    >
    > +++ Rick ---
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >> That is what I am currently doing, however, I think it would be nice to
    >> have a method that can get me the absolute url of another page. Does such
    >> a function exist, or will I need to write it myself? Thanks.
    >>
    >> "Ignacio Machin ( .NET/ C# MVP )" <> wrote in
    >> message
    >> news:...
    >> On Sep 8, 1:50 pm, "Nathan Sokalski" <>
    >> wrote:
    >>> I have a page in my site that I need the absolute url of. Is there a
    >>> function in .NET to which you can pass a relative url or something such
    >>> as
    >>> "~/mydirectory/mypage.aspx" which will return an absolute url? I need
    >>> this
    >>> because at the moment I do not know what the domain name (or if there is
    >>> the
    >>> possibility of the site going in a subdirectory) where the site will
    >>> eventually exist. Also, this will make it easier to test during
    >>> development.
    >>> I need the absolute url because it will be getting sent as part of an
    >>> email.
    >>> Thanks.
    >>>
    >>> Nathan Sokalski
    >>> ://www.nathansokalski.com/

    >>
    >> You can get your current absolute URL by using
    >> Request.Url.AbsoluteUri. you will have to modify the part different
    >> from the current relative url to the one that you want to return.
    >>
    >>

    >
     
    Nathan Sokalski, Sep 9, 2008
    #11
  12. Unfortunately, that does not include the protocol and domain name, it only
    includes the path. Any other ideas?

    "Hillbilly" <> wrote in message
    news:%...
    > Try ResolveUrl("~/dir/filename.asp") which will append the root path of
    > the domain to the virtual path regardless of where the page is requested
    > and compiled.
    >
    >
    >
    > "Nathan Sokalski" <> wrote in message
    > news:Oug$...
    >>I have a page in my site that I need the absolute url of. Is there a
    >>function in .NET to which you can pass a relative url or something such as
    >>"~/mydirectory/mypage.aspx" which will return an absolute url? I need this
    >>because at the moment I do not know what the domain name (or if there is
    >>the possibility of the site going in a subdirectory) where the site will
    >>eventually exist. Also, this will make it easier to test during
    >>development. I need the absolute url because it will be getting sent as
    >>part of an email. Thanks.
    >>
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
     
    Nathan Sokalski, Sep 9, 2008
    #12
  13. Hey Nathan,

    Why don't you try the

    Request.Url.GetLeftPart(UriPartial.Authority)

    statement for the protocol name, domain name and port part?

    Cheers,
    Erjan

    "Nathan Sokalski" <> wrote in message
    news:...
    > Unfortunately, that does not include the protocol and domain name, it only
    > includes the path. Any other ideas?
    >
    > "Hillbilly" <> wrote in message
    > news:%...
    >> Try ResolveUrl("~/dir/filename.asp") which will append the root path of
    >> the domain to the virtual path regardless of where the page is requested
    >> and compiled.
    >>
    >>
    >>
    >> "Nathan Sokalski" <> wrote in message
    >> news:Oug$...
    >>>I have a page in my site that I need the absolute url of. Is there a
    >>>function in .NET to which you can pass a relative url or something such
    >>>as "~/mydirectory/mypage.aspx" which will return an absolute url? I need
    >>>this because at the moment I do not know what the domain name (or if
    >>>there is the possibility of the site going in a subdirectory) where the
    >>>site will eventually exist. Also, this will make it easier to test during
    >>>development. I need the absolute url because it will be getting sent as
    >>>part of an email. Thanks.
    >>>
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>

    >>

    >
    >
     
    Erjan Gavalji, Sep 9, 2008
    #13
    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. Pete
    Replies:
    4
    Views:
    417
  2. wl
    Replies:
    1
    Views:
    4,461
  3. =?Utf-8?B?UGF1bCBCb25mYW50aQ==?=

    Response.Redirect() converts relative URL to absolute URL

    =?Utf-8?B?UGF1bCBCb25mYW50aQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    6,272
    bruce barker \(sqlwork.com\)
    Apr 25, 2006
  4. Rudi Ahlers
    Replies:
    11
    Views:
    846
    Aaron Bertrand [MVP]
    Apr 11, 2004
  5. middletree

    Obtaining URL of previous page

    middletree, May 21, 2004, in forum: ASP General
    Replies:
    11
    Views:
    309
    Joseph
    Jun 20, 2004
Loading...

Share This Page