0

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);
            }
        }
    }

. . . . .

  • meant to add that the requestContext.HttpContext.Request.Headers is null when hosted on the server. It is not null when testing locally.. – vishatstack May 14 '21 at 19:38

1 Answers1

0

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.

Steve
  • 1,266
  • 16
  • 37
  • Thank you Steve. The Request is not null. The Request.Header is null. We are seeing this issue on two different servers running on Windows 2016. Any feature/setting that might be blocking the headers? – vishatstack May 19 '21 at 15:08
  • Sorry, I'm not aware of anything that would cause that. As I say, I would start by creating a more minimal web app and seeing if that works. – Steve May 20 '21 at 15:22