aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

Url Rewrite - No distinction between global and regular rules. #59

Closed jkotalik closed 7 years ago

jkotalik commented 8 years ago

Currently global rules are treated like normal rules, while rather they should be treated to operate on both the path and path base (AFAIK). Global rules:

– Rules in this collection can be defined only on the server level. Global rules are used to define server-wide URL rewriting logic. These rules are defined within the ApplicationHost.config file, and they cannot be overridden or disabled on any lower configuration levels. Global rules always operate on the absolute URL's path (that is, the requested URI without the server name). These rules are evaluated early in the IIS request-processing pipeline (PreBeginRequest event).
davidpeden3 commented 8 years ago

Wait, what requires forwarding? global rules? I don't see that in the description, only that it mutates the full url.

@Tratcher you may be technically correct (i'm not sure, to be honest) and that's what i have implemented. for my use-case, we are using global rules specifically to create a reverse proxy. i went ahead and created a reverse proxy middleware which works for single requests but i'm concerned about concurrency and scale.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory msLoggerFactory, ILogger logger)
{
    msLoggerFactory.AddSerilog(logger);
    RewriteOptions options = new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "RewriteRules.xml");
    app.UseRewriter(options);
    app.RunReverseProxy();
}

without adding app.RunReverseProxy();, the server returns a 404 which makes perfect sense. we require the request forwarding.

i'm not really sure what the purpose of a global rule that rewrites the full url would be if it were not being used to implement a reverse proxy but i guess that's technically out of scope for this issue. it seems like a reverse proxy middleware (as i have implemented separately as seen above) would be a great additional sub-project for this repo. definitely interested to hear your thoughts.

i'll try to get the PRs for both issues (this one and https://github.com/aspnet/BasicMiddleware/issues/55) submitted by this weekend, if not sooner. still need to write some unit tests and do a git pull. you guys appear to have changed some of the code since i originally cloned the repo and fixed one of the bugs that i discovered and also fixed while doing this work.

mikaelm12 commented 7 years ago

Resolved in https://github.com/aspnet/BasicMiddleware/pull/169