Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out in Global.Asax - Application_Start if ASP.NET application running locally

HttpContext.Current.Request.IsLocal is not available in Global.Asax/Application_Start (Request is not available in the context).

How else could I safely determine if my ASP.NET MVC application is started locally or not?

This is to rewrite my web.config conditionally (depending on whether the application is deployed (remote) or in testing (local)).

Thank you!

like image 827
Alex Avatar asked May 21 '10 21:05

Alex


1 Answers

The Application_Start event will be fired when IIS/cassini/whatever loads up your app (way before any HTTP requests have been made).

Reading your comments you want this to be a "one time operation" which really makes no sense. Your application is not so much "started locally" but it may be requested locally and/or remotely several times throughout its life cycle. With this in mind you need to check on each request as David commented.

Maybe, it would be better if you explained a little more what you are trying to achieve?

like image 186
Owen Avatar answered Nov 02 '22 14:11

Owen