Using HttpContext.Current.Request.ServerVariables["SERVER_NAME"] in integrated mode gives an error in IIS7 as per: http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
Is there a replacement I can use in global.asax code for HttpContext.Current.Request.ServerVariables["SERVER_NAME"]?
This would be similar to using
String strPath =
HttpContext.Current.Server.MapPath(HttpRuntime.AppDomainAppVirtualPath);
instead of
//String strPath =
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ServerVariables["PATH_INFO"]);
Best Answer
Since there's no Request context in the pipeline during app start anymore, I can't imagine there's any way to guess what server/port the next actual request might come in on.
Here's what I'm using when not in Classic Mode. The overhead is negligible.