【发布时间】:2017-02-09 11:55:12
【问题描述】:
当没有为请求指定路径时,这是进行永久重定向的正确方法吗?
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);
});
【问题讨论】:
标签: asp.net-core asp.net-core-mvc url-redirection http-redirect response.redirect