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

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

How else can I safely determine if an ASP.NET MVC application is running locally or not?

This is necessary to rewrite my web.config conditionally (depending on whether the application is being deployed (remotely) or tested (locally)).

Thanks!

+6
c # asp.net-mvc localhost global-asax
source share
2 answers

The Application_Start event will be fired when IIS / cassini / independently loads your application (the path before any HTTP requests are made).

When reading your comments, you want it to be a β€œone-time operation,” which does not really make sense. Your application is not so much "launched locally", but it can be requested locally and / or remotely several times throughout the life cycle. With that in mind, you need to check every request, as David commented.

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

+1
source share

It might be more appropriate to check this in the BeginRequest method instead of Application_Start , because the first request may be local, but later you can call the application in another domain and it will no longer be local.

0
source share

All Articles