没有指定路径时,ASP.NET Core permament重定向

时间:2016-09-30 20:11:53

标签: asp.net-core asp.net-core-mvc url-redirection http-redirect response.redirect

如果没有为请求指定路径,这是否是执行永久重定向的正确方法?

BroadcastReceiver

更新1

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); }); 似乎包含context.Request.Path

/

1 个答案:

答案 0 :(得分:0)

根据UriHelper的实施情况,应使用HttpRequest.PathBase abd HttpRequest.Path

var combinedPath = (pathBase.HasValue || path.HasValue) 
                   ? (pathBase + path).ToString() : "/";

ProxyMiddleware类中的相同逻辑:

var uriString = $"{_options.Scheme}://{_options.Host}:{_options.Port}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";