Alternative to getting ServerVariables from Request

331 views Asked by At

I have my webservice running on IIS in Integrated mode. In this mode, HttpContext.Request throws exception, when is called from Application_Start method.

// app is HttpApplication
var serverName = app.Context.Request.ServerVariables["SERVER_NAME"];

The above statement would throw System.Web.HttpException: Request is not available in this context

Is there somewhere else, where I can retrieve ServerVariables from, within Application_Start?

1

There are 1 answers

0
VDWWD On

You can use HostingEnvironment

System.Web.Hosting.HostingEnvironment

It has a lot of properties you can use