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

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 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