ASP.NET and Current hostname and Port

J

John Q

In Silverlight Application it's possible to query current Application's
hostname and port using namespace Windows.System and code like
below

String hostname = Application.Current.Host.Source.Host + ":" +
Application.Current.Host.Source.Port;

I tried to find out how to do this in ASP.NET Application but couldn't
succeeded.
Does anyone know how to get same result in ASP.NET Applicatio?

Cheers,

JQ
 
J

Juan T. Llibre

re:
!> I tried to find out how to do this in ASP.NET Application but couldn't succeeded.
!> Does anyone know how to get same result in ASP.NET Applicatio?

Dim fullappname as string = Request.Url.Host
Dim port as string = Request.ServerVariables("SERVER_PORT")
Dim MyUrl As Uri = Request.Url
Dim fullappnameProtocolAndPort As String = "The full URL, protocol and port for the application is : " _
& Server.HtmlEncode(MyUrl.Scheme) & "://" & fullappname & ":" & port & Request.ApplicationPath & "/"

That code will also give you the correct protocol.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top