April 9, 2009

How do you programmatically determine if an ASP.NET application is running locally




A user recently popped up a question on the forums asking if it was possible to determine that his asp.net app is running on the local machine. Well there were suggestions to check for the local address 127.0.0.1 or check http://localhost.

How to do this the reliable way, a very simple solution is to use the 'isLocal' property of the Request class as shown below:

C#


protected void Page_Load(object sender, EventArgs e)


{


    if (HttpContext.Current.Request.IsLocal)


    {


        Response.Write("App is local");


    }


}




VB.NET


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)


        If HttpContext.Current.Request.IsLocal Then


            Response.Write("App is local")


        End If


    End Sub




'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "How do you programmatically determine if an ASP.NET application is running locally"
  1. Kiosker said...
    April 13, 2009 10:38 PM

    Verry good tip

 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions