473,386 Members | 1,860 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,386 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
12 1286
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
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13

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...
13
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.