问题描述
我的网站中有一个页面,我需要绝对的网址。在.NET中是否有一个
函数可以传递一个相对的url或者诸如
"〜/ mydirectory / mypage.aspx"哪个会返回一个绝对的网址?我需要这个
,因为目前我不知道该域名是什么(或者如果网站的子目录中存在
的可能性)该网站将在哪里
最终存在。此外,这将使开发过程中更容易测试。
我需要绝对网址,因为它将作为电子邮件的一部分发送。
谢谢。
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
nj********@hotmail.com
http://www.nathansokalski.com/
推荐答案
您可以使用
Request.Url.AbsoluteUri获取当前的绝对URL。你必须将当前相对网址不同的部分修改为你想要返回的部分。
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.
这篇关于获取页面的绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!