Reputation: 1
The code below works locally but not when hosted on the server (Win 2016). Any ideas?
public abstract class BaseController : Controller {
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
Session["DeviceInfo"] = new Device();
if (WebProvider.ActiveProvider != null)
{
if ((requestContext.HttpContext.Request.Headers != null) && (requestContext.HttpContext.Request.Headers.Count > 0) && (requestContext.HttpContext.Request.Headers.HasKeys()))
{
// Perform device detection on the headers provided in the
// request.
var match = WebProvider.ActiveProvider.Match(
requestContext.HttpContext.Request.Headers);
Session["DeviceInfo"] = new Device(match);
}
}
}
. . . . .
Upvotes: 0
Views: 164
Reputation: 1316
I'm not sure what scenario would cause the Request.Headers collection to be null, but I would assume it must be something to do with the hosting configuration / environment.
I would suggest stripping it back to a very basic 'hello world' style web page that just displays the names and values of any headers. If that doesn't work then you've definitely got a configuration/environment issue. If it does then you can start adding bits in until you find what is causing the problem.
Upvotes: 0