tags:

views:

214

answers:

0

In my C# web application, I manage switching between http and https pages in code as follows:

      if (pageSettingsInfo.RequiresSSL)
  {
   if (!HttpContext.Current.Request.IsSecureConnection)
   {
    HttpRequest request=HttpContext.Current.Request;
    string url = request.Url.ToString().Replace(request.Url.Authority, request.UrlReferrer.Authority);
    string secureUrl = GetSecureUrl(url);      
    HttpContext.Current.Response.Redirect(secureUrl, true);
   }
  }

in my dev environment, it works perfectly OK. In my live environment it works fine. However in my staging environment it throws an error because the request.url is null. This is an improvement on an earlier situation where it was pointing to the live url.

I have no ideas why this is the case. Rebuilding the staging environment is not a viable option, and it doesn't answer why it happens anyway - how can the request get to the code if it doesn't come from anywhere? It is more of an issue now, as the same problem has been seen on one of our pre-live installations, for the first time. Without knowing what its wrong, we can do nothing about this.

Any assistance would be much appreciated