Finding out web application URL

M

m

Hello

I need to find out full URL of my application name, I tried using
Request.ServerVariables["SERVER_NAME"] but it returns only serverername,
and I need virtual directory name as well.

Thnx in advance
 
M

MWells

"URL" will give you the full path, not including hostname. I believe there
is also a "RAW_URL" or "URL_RAW" that gives you the full path.
 
M

m

MWells said:
"URL" will give you the full path, not including hostname. I believe there
is also a "RAW_URL" or "URL_RAW" that gives you the full path.

Yes, I found that variable, but the problem again is that i don't know
if path given starts with a virtual directory or plain directory. The
idea was to separate servername + virual_directory part from "plain"
directory path.
 
J

John Blair

Use APPL_PHYSICAL_PATH for dos directory name or PATH_INFO for virtual
directory name.
 
J

Juan T. Llibre

Using the "Request" .Net Framework class ( System.Web.HttpRequest )
should be a little faster and more efficient than using Request.ServerVariables.

RequestUrl.aspx:
-------------------------
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim url1 As String = Request.Url.ToString
Label1.Text = url1
End Sub
</script>
<head>
<title>Retrieve Full URL</title>
</head>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label" Width="238px" Height="19px"></asp:Label><br />
</div>
</form>
</body>
</html>
-----------

If you only need the Application's virtual path, use :
Request.ApplicationPath.ToString

If you only need the full virtual path, use :
Request.RawUrl.ToString



Juan T. Llibre
ASP.NET MVP
===========
MWells said:
"URL" will give you the full path, not including hostname. I believe there
is also a "RAW_URL" or "URL_RAW" that gives you the full path.

Hello

I need to find out full URL of my application name, I tried using
Request.ServerVariables["SERVER_NAME"] but it returns only serverername,
and I need virtual directory name as well.

Thnx in advance
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top