如果没有为请求指定路径,这是否是执行永久重定向的正确方法?
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
/
答案 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}";