Obtaining the Absolute URL of a page

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

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
(e-mail address removed)
http://www.nathansokalski.com/
 
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
(e-mail address removed)://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.
 
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?

Does Request.Url help?

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

message
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
(e-mail address removed)://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.
 
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.

message


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?
 
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.
 
In case you didn't notice, I did post it to
microsoft.public.dotnet.framework.aspnet.
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

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

message


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?
 
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 ---
 
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.
 
Unfortunately, that does not include the protocol and domain name, it only
includes the path. Any other ideas?
 
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
 
Back
Top