Obtaining the Absolute URL of a page

  • Thread starter Nathan Sokalski
  • 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

Ignacio Machin ( .NET/ C# MVP )

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

Nathan Sokalski

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
 
N

Nathan Sokalski

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

Ignacio Machin ( .NET/ C# MVP )

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

Hillbilly

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

Nathan Sokalski

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

rstrahl

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

Nathan Sokalski

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

Nathan Sokalski

Unfortunately, that does not include the protocol and domain name, it only
includes the path. Any other ideas?
 
E

Erjan Gavalji

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top