首页 > 解决方案 > Asp.net Middleware ReWrite 没有将请求转发到预期的 url

问题描述

我只是试图通过 ReWrite 中间件将所有传入请求路由到特定页面,但我没有得到想要的结果。事实上,网站的行为就好像中间件甚至不在管道中一样。我已将逻辑放在 app.UseEndpoints 之前的启动文件中。

var isMaintenance = true;

if (isMaintenance)
{
    var options = new RewriteOptions()
          .AddRewrite(@"^(.*)", "/maintenance", true);
    app.UseRewriter(options);
}

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
    endpoints.MapBlazorHub();
    endpoints.MapFallbackToPage("/_Host");
});

标签: c#asp.netasp.net-coreasp.net-core-3.0asp.net-core-middleware

解决方案


推荐阅读