2
当没有为请求指定路径时,这是做永久重定向的正确方法吗?当没有指定路径时,ASP.NET Core permament重定向
app.Use(next => context =>
{
if (string.IsNullOrWhiteSpace(context.Request.Path))
{
var builder = new UriBuilder(context.Request.Scheme, "site to redirect");
context.Response.Redirect(builder.ToString(), true);
}
return next(context);
});
更新1
似乎context.Request.Path
包括/
app.Use(next => context =>
{
if (context.Request.Path.Value.Length <= 1)
{
var builder = new UriBuilder(context.Request.Scheme, "www.plaMobi.com");
context.Response.Redirect(builder.ToString(), true);
}
return next(context);
});