473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Obtaining the Absolute URL of a page

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
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 8 '08 #1
13 2456
Does Request.Url help?

Kalpesh

On Sep 8, 10:50*am, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://www.nathansokalski.com/
Sep 8 '08 #2
On Sep 8, 1:50*pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://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.

Sep 8 '08 #3
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" <sh*********@gmail.comwrote in message
news:1b**********************************@z66g2000 hsc.googlegroups.com...
Does Request.Url help?

Kalpesh

On Sep 8, 10:50 am, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://www.nathansokalski.com/

Sep 8 '08 #4
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 )" <ig************@gmail.comwrote in
message
news:6b**********************************@z72g2000 hsb.googlegroups.com...
On Sep 8, 1:50 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://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.
Sep 8 '08 #5
On Sep 8, 4:06*pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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 )" <ignacio.mac...@gmail.comwrote in
messagenews:6b**********************************@z 72g2000hsb.googlegroups..com...
On Sep 8, 1:50 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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 suchas
"~/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
njsokal...@hotmail.comhttp://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?
Sep 8 '08 #6
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:d9**********************************@73g2000h sx.googlegroups.com...
Why don't you post your question in the ASPNET NG?
He did - he crossposts everything...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 8 '08 #7
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" <ns*******@kyledavidgroup.comwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>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
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 8 '08 #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
nj********@hotmail.com
http://www.nathansokalski.com/

"Hillbilly" <so******@somewhere.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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" <ns*******@kyledavidgroup.comwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>>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
nj********@hotmail.com
http://www.nathansokalski.com/

Sep 8 '08 #9
In case you didn't notice, I did post it to
microsoft.public.dotnet.framework.aspnet.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:d9**********************************@73g2000h sx.googlegroups.com...
On Sep 8, 4:06 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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 )" <ignacio.mac...@gmail.comwrote in
messagenews:6b**********************************@z 72g2000hsb.googlegroups.com...
On Sep 8, 1:50 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://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?
Sep 8 '08 #10
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" <ns*******@kyledavidgroup.comwrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
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 )" <ig************@gmail.comwrote in
message
news:6b**********************************@z72g2000 hsb.googlegroups.com...
On Sep 8, 1:50 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://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.

Sep 9 '08 #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" <ri********@hotmail.comwrote in message
news:C4**********************************@microsof t.com...
>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" <ns*******@kyledavidgroup.comwrote in message
news:Ot**************@TK2MSFTNGP02.phx.gbl...
>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 )" <ig************@gmail.comwrote in
message
news:6b**********************************@z72g200 0hsb.googlegroups.com...
On Sep 8, 1:50 pm, "Nathan Sokalski" <nsokal...@kyledavidgroup.com>
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
njsokal...@hotmail.comhttp://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.


Sep 9 '08 #12
Unfortunately, that does not include the protocol and domain name, it only
includes the path. Any other ideas?

"Hillbilly" <so******@somewhere.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
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" <ns*******@kyledavidgroup.comwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>>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
nj********@hotmail.com
http://www.nathansokalski.com/

Sep 9 '08 #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" <ns*******@kyledavidgroup.comwrote in message
news:uy**************@TK2MSFTNGP02.phx.gbl...
Unfortunately, that does not include the protocol and domain name, it only
includes the path. Any other ideas?

"Hillbilly" <so******@somewhere.comwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>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" <ns*******@kyledavidgroup.comwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
>>>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
nj********@hotmail.com
http://www.nathansokalski.com/

Sep 9 '08 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gregl | last post by:
Anyone know how to obtain the true size of the html document's body? The control contains the size that the control was set to. The body object appears to contain the same size. That information...
3
by: Sir Loin of Beef | last post by:
I have a root directory with 1 subdirectory(myphoto), and 2 files. Inside the myphoto subdirectory, I have 1 html page and another image. Root dir: <myphoto> 01.jpg watermark.php myphoto:
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
6
by: Pete | last post by:
Hi, I am writing a pre-handler page for aspx pages, in which I want to call a custom method on the code-behind class file for the aspx page. In order to do this I need to somehow get the...
1
by: Terry Mulvany | last post by:
Grettings, Normally I can use Request.RawUrl to get the 'current' page (amongst many other things). But in the case of using a Server.Transfer but the path from the root of the site . So if...
12
by: Nathan Sokalski | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.