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.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- How to store image outside of the website's ro
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
You can check the Request.IsLocal property
In a MVC view / ASP page / code behind class:
In an MVC controller :
This worked for me with Application_Start
To know more about how IsDevelopmentEnvironment is set, please look at the following thread.
In ASP.NET, what determines the value of HostingEnvironment.IsDevelopmentEnvironment?
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.
See HttpRequest.IsLocal
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.