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 app is running on the local machine. Well there were suggestions to check for the local address 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:


protected void Page_Load(object sender, EventArgs e)


    if (HttpContext.Current.Request.IsLocal)


        Response.Write("App is local");




    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

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) 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 is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

1 comment:

Kiosker said...

Verry good tip