Application Address

  • Thread starter Thread starter Shimon Sim
  • Start date Start date
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
 
start here maybe
for(int i = 0;i < Request.ServerVariables.Count;i++)

{

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

}
 
<%@ 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
===========
 
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
===========
 
thanks. Request.Url has plenty info and works as expected.
What's wrong with RawUrl??
Shimon.
 
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
===========
 
/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
===========
 
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
===========
 
Back
Top