如何获取虚拟根的完整URL [英] How to get full url of virtual root
本文介绍了如何获取虚拟根的完整URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个简单的问题:
如何获取我网站的虚拟路径的完整网址。
例如。在我的开发机器上,它是 http:// localhost:6786 / website1 并且在
生产服务器它将是 http://www.mycompany.dk 。
/ Thomas
Hi
I have a simple question:
How do I get the full url of the virtuel path of my website.
Eg. on my dev machine it is http://localhost:6786/website1 and on the
production server it will be http://www.mycompany.dk.
/Thomas
推荐答案
Request.Url.ToString
查看演示: http://asp.net.do /test/requesturl.aspx
Juan T. Llibre,asp.net MVP
aspnetfaq.com: http://www.aspnetfaq.com/
asp.net faq: http://asp.net.do/faq/
foros de asp.net,en espa?ol: http://asp.net.do/ foros /
======================= ============
" Thomas Jespersen" < tj*@nospam.mentum.dk>在留言中写道
news:uc ************** @ TK2MSFTNGP02.phx.gbl ...
Request.Url.ToString
Check out a demo at : http://asp.net.do/test/requesturl.aspx
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
"Thomas Jespersen" <tj*@nospam.mentum.dk> wrote in message
news:uc**************@TK2MSFTNGP02.phx.gbl...
嗨
我有一个简单的问题:
如何获得我网站的虚拟路径的完整网址。
例如。在我的开发机器上,它是生成服务器上的 http:// localhost:6786 / website1 它将是
http://www.mycompany.dk 。
/ Thomas
Hi
I have a simple question:
How do I get the full url of the virtuel path of my website.
Eg. on my dev machine it is http://localhost:6786/website1 and on the production server it will be
http://www.mycompany.dk.
/Thomas
如果您只想要一个客户有效的参考:
Dim root As String = Me。 ResolveUrl(〜)
如果你真的希望整个URL到根,你可以构建一个函数,
注意它是'未经测试但我不能想到任何无法工作的情况。
公共函数AppRoot()As String
Dim appRelativeRoot As String = Me.ResolveUrl("〜")
Dim originalUrl As String = Me.Request.Url.ToString
Dim pos As Integer = originalUrl.IndexOf(appRelativeRoot)
Dim path As String = appRelativeRoot
如果pos> 0然后
path = originalUrl.Substring(0,pos + appRelativeRoot.Length)
结束如果
返回路径
结束功能
If you just want a client valid reference:
Dim root As String = Me.ResolveUrl("~")
If you actually want the whole URL to the root, you could build a function,
note it''s untested but I can''t think of any senarios where it wouldn''t work.
Public Function AppRoot() As String
Dim appRelativeRoot As String = Me.ResolveUrl("~")
Dim originalUrl As String = Me.Request.Url.ToString
Dim pos As Integer = originalUrl.IndexOf(appRelativeRoot)
Dim path As String = appRelativeRoot
If pos > 0 Then
path = originalUrl.Substring(0, pos + appRelativeRoot.Length)
End If
Return path
End Function
拉里。
re:
Hi, Larry.
re:
如果你真的希望整个URL到根,你可以构建一个函数
为什么要经历这些箍,如果Request.Url.ToString得到整个URL?
Juan T. Llibre,asp.net MVP
aspnetfaq.com: http://www.aspnetfaq.com/
asp.net faq: http://asp.net.do/faq/
foros de asp.net,en espa?ol:< a rel =nofollowhref =http://asp.net.do/foros/target =_ blank> http://asp.net.do/foros/
===================================
" Larry Charlton" <拉*********** @ discussions.microsoft.com>在消息中写道
新闻:C8 ********************************** @ microsof t.com ...如果你只想要一个客户端有效的参考:
Dim root As String = Me.ResolveUrl("〜")
如果你真的想要整个URL到根,你可以构建一个函数,
注意它是未经测试但我不能想到任何无法工作的情况。
Public Function AppRoot()作为String
Dim appRelativeRoot As String = Me.ResolveUrl("〜")
Dim originalUrl As String = Me.Request.Url.ToString
Dim pos As Integer = originalUrl.IndexOf( appRelativeRoot)
Dim path As String = appRelativeRoot
如果pos> 0然后
path = originalUrl.Substring(0,pos + appRelativeRoot.Length)
结束如果
返回路径
结束功能
If you actually want the whole URL to the root, you could build a function
Why go through those hoops, if Request.Url.ToString gets the whole URL ?
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
"Larry Charlton" <La***********@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com... If you just want a client valid reference:
Dim root As String = Me.ResolveUrl("~")
If you actually want the whole URL to the root, you could build a function,
note it''s untested but I can''t think of any senarios where it wouldn''t work.
Public Function AppRoot() As String
Dim appRelativeRoot As String = Me.ResolveUrl("~")
Dim originalUrl As String = Me.Request.Url.ToString
Dim pos As Integer = originalUrl.IndexOf(appRelativeRoot)
Dim path As String = appRelativeRoot
If pos > 0 Then
path = originalUrl.Substring(0, pos + appRelativeRoot.Length)
End If
Return path
End Function
这篇关于如何获取虚拟根的完整URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文