How to get full url of virtual root

G

Guest

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
 
M

Michael Mooney

T

Thomas Jespersen

Hi Juan

Request.ApplicationPath! Why didn't I see that. I was going nots. Thanks.

Here is the final method, which also takes the port number and protocol
(http/https) into account:

private string FullApplicationPath()
{
return Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,
string.Empty) + Request.ApplicationPath;
}

All the other methods simply didn't work, because they either removed the
Virtual directory or assumed that the everything else was on the same level
as the Request.

/Thomas
 
M

Michael Mooney

Juan T. Llibre said:
re:

Because this is an ASP.NET newsgroup ?
*All* questions here are supposed to be related to ASP.NET.

And, of course, ASP.NET works over http.

And, of course, ASP.NET also works over https. It can also include a port
number.

Hardcoding it to always be http is just a bad idea.
 

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

Top