Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Properties of the AuthorizationContext.HttpContext.Connection object passed in to IAuthorizationFilter.OnAuthorization are default values

$
0
0

I'm trying to use the following filter in an ASP.NET 5 RC1 web app:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,
    Inherited = true, AllowMultiple = false)]
public class RequireHttpsRemotelyAttribute : RequireHttpsAttribute
{
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        if (!filterContext.HttpContext.Connection.IsLocal)
        {
            base.OnAuthorization(filterContext);
        }
    }
}

I have tried both adding it as an attribute on controllers and by using the following code in Startup.ConfigureServices:

services.Configure<MvcOptions>(options =>
{
    options.Filters.Add(new RequireHttpsRemotelyAttribute());
});

Every time the RequireHttpsRemotely.OnAuthorization method is called, all of the properties of filterContext.HttpContext.Connection are default  values. For example, IsLocal is false even when loaded locally, LocalIpAddress is null, RemoteIpAddress is null, etc. Some properties on filterContext.HttpContext.Request (such as IsHttps) are also always default values.

I am seeing the same behavior when running in Kestrel, IIS Express, and Azure.

Is anyone else seeing this behavior? And any ideas about how to populate the HttpContext.Connection properties?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>