Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

IHttpConnectionFeature is null for Windows 7 (IIS 8), but works on Windows 10. #51

Closed
pauldotknopf opened this issue Jan 5, 2016 · 12 comments
Assignees
Milestone

Comments

@pauldotknopf
Copy link

Is this expected? Bug?

@davidfowl
Copy link
Member

Can you provide more details? Do you have a sample that we can run? Something on github would be best

@Tratcher
Copy link
Member

Tratcher commented Jan 5, 2016

At least package versions and startup code please.

@pauldotknopf
Copy link
Author

https://github.com/theonlylawislove/temp-aspnet-IISIntegration-issues-51

When running through IIS, I get "No connection feature..." as the response to the request.

> dnx --version
Microsoft .NET Execution environment
 Version:      1.0.0-rc1-16202
 Type:         Clr
 Architecture: x86
 OS Name:      Windows
 OS Version:   6.1
 Runtime Id:   win7-x86

I also have ran through all the instructions for publishing aspnet 5 to IIS. I am using HTTP Platform Handler 1.2.

@guardrex
Copy link
Contributor

guardrex commented Jan 7, 2016

aspnet/HttpAbstractions#309 oops! no Done label

@pauldotknopf
Copy link
Author

@guardrex, as far as I can tell, that change was not made. Correct? I'm not sure what your trying to say.

@Tratcher
Copy link
Member

Tratcher commented Jan 7, 2016

Kestrel didn't populate IHttpConnectionFeature in rc1, but UseIISPlatformHandler would read the x-forwarded-for header and populate it for you. There's a known issue with UseIISPlatformHandler in rc1 where it may fail if the x-forwarded-for address included a port (8ee803d). Have your application display the request headers received. #17 (comment)

@pauldotknopf
Copy link
Author

New output:

No connection feature...
Cache-Control:max-age=0
Connection:Keep-Alive
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Host:skimur.com
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Upgrade-Insecure-Requests:1
X-Forwarded-For:96.243.247.112:24093
X-Forwarded-Proto:https
X-Original-Proto:http

@pauldotknopf
Copy link
Author

Any recommendations for a work around? Should I parse this header myself, and add my own IHttpConnectionFeature implementation in some middlware?

@davidfowl
Copy link
Member

@Tratcher is that fixed in RC2? or RC1-update1?

@theonlylawislove you could copy the code from the new IISPlatformHandler middleware if you're on RC1.

@guardrex
Copy link
Contributor

guardrex commented Jan 9, 2016

Is this it? https://github.com/aspnet/BasicMiddleware/blob/d1a0edb87ea4f24403c9b7273db41a4bfcab6e96/src/Microsoft.AspNet.HttpOverrides/OverrideHeaderMiddleware.cs#L50

OR ... you could try this ...#17 (comment) which will probably get you hacked, broke, fired, and prosecuted! 😄

@pauldotknopf
Copy link
Author

Here is a quick piece of middleware that fixed this issue, in case someone needs it fixed pronto.

public class IISIntegrationHackMiddlerware
{
    // https://github.com/aspnet/IISIntegration/issues/51

    private readonly RequestDelegate _next;

    public IISIntegrationHackMiddlerware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task Invoke(HttpContext context)
    {
        if (context.Request.Headers.ContainsKey("X-Forwarded-For"))
        {
            var header = context.Request.Headers["X-Forwarded-For"];
            if (header.Count > 0)
            {
                var forwardFor = header[0];
                if (!string.IsNullOrEmpty(forwardFor))
                {
                    if (forwardFor.Contains(":"))
                    {
                        forwardFor = forwardFor.Substring(0, forwardFor.LastIndexOf(":"));
                        context.Request.Headers["X-Forwarded-For"] = forwardFor;
                    }
                }
            }
        }

        await _next(context);
    }
}

Register it before you register UseIISPlatformHandler.

@Tratcher
Copy link
Member

@davidfowl @guardrex Yes, that logic was fixed and moved to OverrideHeadersMiddleware.

@Tratcher Tratcher added this to the 1.0.0-rc2 milestone Jan 15, 2016
@Tratcher Tratcher self-assigned this Jan 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants