Application Address

S

Shimon Sim

Hi
I need to get application address that will look like this
http://www.mysite.com
I tried already Request.FilePaht that the documentation says that it returns
the full path of the request including host name but on my machine for some
reason it only returns virtual path and is equal RawUrl.

What's wrong? How can I get host name programmatically?
Shimon
 
C

Curt_C [MVP]

start here maybe
for(int i = 0;i < Request.ServerVariables.Count;i++)

{

Response.Write(Request.ServerVariables.ToString() + "<br>");

}
 
J

Juan T. Llibre

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim dnsname As String = Request.ServerVariables("HTTP_HOST")
Label1.Text = dnsname
End Sub
</script>
<head>
<title>Retrieve Server DNS Name</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>


Juan T. Llibre
ASP.NET MVP
===========
 
J

Juan T. Llibre

You can also use Request.Url.Host

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim dnsname As String = Request.Url.Host
Label1.Text = dnsname
End Sub
</script>
<head>
<title>Retrieve Server DNS Name</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>



Juan T. Llibre
ASP.NET MVP
===========
 
S

Shimon Sim

thanks. Request.Url has plenty info and works as expected.
What's wrong with RawUrl??
Shimon.
 
S

Shimon Sim

Thanks Juan
Shimon.
You can also use Request.Url.Host

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim dnsname As String = Request.Url.Host
Label1.Text = dnsname
End Sub
</script>
<head>
<title>Retrieve Server DNS Name</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>



Juan T. Llibre
ASP.NET MVP
===========
 
K

Karl Seguin

/me raises an eyebrow

--
MY ASP.Net tutorials
http://www.openmymind.net/


You can also use Request.Url.Host

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim dnsname As String = Request.Url.Host
Label1.Text = dnsname
End Sub
</script>
<head>
<title>Retrieve Server DNS Name</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>



Juan T. Llibre
ASP.NET MVP
===========
 
J

Juan T. Llibre

I'm a quick study, Karl.

;-)

Actually, I don't know why that
didn't work when I first tested it.

The first time I ran it, it only returned the IP address.

When I ran it again, after you objected, it returned
what it's supposed to return: the hostname.

I attribute it to evil internet pixies. :)



Juan T. Llibre
ASP.NET MVP
===========
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message /me raises an eyebrow

--
MY ASP.Net tutorials
http://www.openmymind.net/


You can also use Request.Url.Host

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim dnsname As String = Request.Url.Host
Label1.Text = dnsname
End Sub
</script>
<head>
<title>Retrieve Server DNS Name</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>



Juan T. Llibre
ASP.NET MVP
===========
 

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,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top