In my WCF app i have a Global.asax.cs with something like this to retrieve the base URL:
protected void Application_Start(object sender, EventArgs e)
{
string baseURL = System.Web.HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
}
In my development box (localhost) it works fine. But when i push it to production the System.Web.HttpContext.Current.Request returns null.
Anyone know why this might be happening?
This is likely because in development your App Pool is in "Classic" mode (or on IIS 6-).
In production, your App Pool is set to "Integrated". Integrated does not allow you to access the Request object in Application_Start.
Classic behavior allows this because the only way to start an ASP.NET application in Classic Mode is with the first request. In Integrated mode, the application may start by other means than a request (Such as application warm-up).
You can find more information on why, and how to fix this on IIS's Website.
Ultimately, you have two options:
Request object in Application_Start.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With