I want to know if there is a recommended way of determining if an asp application is running locally. At the moment I use the Request object and do a string search for localhost or 127.0.0.1 on the server variable but this has several limitations. The biggest one being that the Request object is not always available when I need it.
+1
A:
Request is not always available in ASP.NET environment?
HttpContext and its properties Request/Response are initialized as soon as the server starts processing the page. So at any place you can execute c# code in your page life cycle you should be able to check the request url.
Roman R.
2009-03-28 01:08:59
I didn't realise that I could use the HttpContext class to access the Request object.
Sean
2009-03-30 23:17:26
Out of curiosity, what other method of accessing the Request object is available? Thanks :)
Roman R.
2009-03-31 16:21:51
System.Web.UI.Page.Request
Sean
2009-03-31 22:45:07
A:
Request.IsLocal is the same as checking for 127.0.0.1 or ::1. See this post: http://forums.asp.net/p/1065813/4081335.aspx.
ZLA
2010-09-16 15:31:07
Yes, but using a standard library call conveys the intention of the code better, IMO. I would prefer to use the library rather than write my own code to do such a simple thing.
Sean
2010-09-17 04:31:28
I agree. I just wanted to point out that since the designated answer may be the same code as what the poster was using, the answer may have the same limitations.
ZLA
2010-09-28 19:39:43