2

リクエストにパスが指定されていない場合、これは永続的なリダイレクトを行う正しい方法ですか?ASP.NETコアのパーマネントがパスが指定されていないときにリダイレクト

 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.PathUriHelper実装するため/

 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); 
     }); 

答えて

0

を含む、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}"; 
関連する問題