1
Apacheは書き換えられたURLに基づいて提供するファイルを選択しますが、元のURLはスクリプトに渡されます。Kestrelで書き直した後の元のURLを取得
Kestrelは、書き換えられたURLをパイプラインに渡します(HttpContext.Request.Path
からアクセス可能)。
ミドルウェアから書き直して元のURLにアクセスすることはできますか?
Apacheは書き換えられたURLに基づいて提供するファイルを選択しますが、元のURLはスクリプトに渡されます。Kestrelで書き直した後の元のURLを取得
Kestrelは、書き換えられたURLをパイプラインに渡します(HttpContext.Request.Path
からアクセス可能)。
ミドルウェアから書き直して元のURLにアクセスすることはできますか?
@Tsengから発行された指示に従います。私のテストはRewriteMiddlewareをラップしますが、別のミドルウェアが必要な場合があります。
public class P7RewriteMiddleware
{
private RewriteMiddleware _originalRewriteMiddleware;
public P7RewriteMiddleware(
RequestDelegate next,
IHostingEnvironment hostingEnvironment,
ILoggerFactory loggerFactory,
RewriteOptions options)
{
_originalRewriteMiddleware = new RewriteMiddleware(next, hostingEnvironment, loggerFactory, options);
}
/// <summary>
/// Executes the middleware.
/// </summary>
/// <param name="context">The <see cref="HttpContext"/> for the current request.</param>
/// <returns>A task that represents the execution of this middleware.</returns>
public new Task Invoke(HttpContext context)
{
var currentUrl = context.Request.Path + context.Request.QueryString;
context.Items.Add("original-path", currentUrl);
return _originalRewriteMiddleware.Invoke(context);
}
}
その後、私の認証フィルタで使用されます。
if (spa.RequireAuth)
{
context.Result = new RedirectToActionResult(Action, Controller,
new { area = Area, returnUrl = context.HttpContext.Items["original-path"] });
}
ミドルウェアを作成し、パイプラインで(HttpContext.Itemsやその他の手段で)パイプラインに渡してください。 – Tseng