How are OwinContext.Request.Path and PathBase populated?

前端 未结 1 914
野性不改
野性不改 2021-02-20 16:21

I\'m writing my own OWIN middleware for OpenID Connect authorization code flow, based on other examples in the Katana Project.

As part of this I have to construct a coup

相关标签:
1条回答
  • 2021-02-20 16:58

    When using the construct

    app.Map("/login", map => [...]
    

    This uses

    Owin.MapExtensions.Map
    

    which constructs an instance of

    Microsoft.Owin.Mapping.MapMiddleware
    

    for the code which needs running.

    The behaviour I have seen is explained in the Invoke method of this middleware:

    public async Task Invoke(IDictionary<string, object> environment)
    {
        IOwinContext context = new OwinContext(environment);
    
        PathString path = context.Request.Path;
    
        PathString remainingPath;
        if (path.StartsWithSegments(_options.PathMatch, out remainingPath))
        {
            // Update the path
            PathString pathBase = context.Request.PathBase;
            context.Request.PathBase = pathBase + _options.PathMatch;
            context.Request.Path = remainingPath;
    
            await _options.Branch(environment);
    
            context.Request.PathBase = pathBase;
            context.Request.Path = path;
        }
        else
        {
            await _next(environment);
        }
    }
    

    Basically the code changes the Path and PathBase before it runs the delegate (await _options.Branch(environment) ), then sets these back to the original values after execution is complete.

    Hence the behaviour I had seen is explained.

    0 讨论(0)
提交回复
热议问题