URL書き換えの設定
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
HTMLの相対リンクが高度なSitecoreエディタと統合される際に適切にレンダリングされるようにするため、Headless Servicesは返還されたマークアップ内の相対URLを絶対的なURLに書き換えます。この処理に含まれるデフォルトのタグと属性は以下の通りです。
タグ名
属性名
audio
src
img
src, srcset
link
href
script
src
source
src, srcset
track
src
video
poster, src
URL書き換えを無効にする
Headless Servicesが返されるマークアップ内の相対的なURLを絶対URLに書き換えたくない場合は、URL書き換えを無効にできます。
URL書き換えを無効にするには:
-
設定済みのhttpレンダリングエンジンでは、オプションEnableRelativeLinkProcessingの値をfalseに変更してください:
false
書き換えたHTML属性の設定
URLの書き換えは型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを上書きすることでカスタマイズできます。
書き換えたHTML属性を設定するには:
-
nugetパッケージを参照Sitecore.JavaScriptServices.ViewEngine.Http。
-
型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを継承する型を作成します。
-
ResolveAllを上書きしてResolveForId。
-
基本メソッドで返されたLinkAttributeMapオプションフィールドを上書きします:
public override IEnumerable
ResolveAll(RenderEngineOptions runtimeOptions = null) { var optionsCollection = base.ResolveAll(runtimeOptions); foreach (var options in optionsCollection) { options.LinkAttributeMap.Add("video", new { "poster", "src" }); } return optionsCollection; }
public override HttpRenderEngineOptions ResolveForId(string id, RenderEngineOptions runtimeOptions = null) { var options = base.ResolveForId(id, runtimeOptions); options.LinkAttributeMap.Add("video", new { "poster", "src" }); return options; }
-
依存関係構成器を作成し、IRenderEngineOptionsResolverサービス登録をオーバーライドします:
public void Configure(IServiceCollection serviceCollection) { serviceCollection.AddTransient<IHttpRenderEngineFactory, HttpRenderEngineFactory>(); serviceCollection.AddTransient<IConfigurationReader, XmlConfigurationReader>(); serviceCollection.AddSingleton<IHttpSessionStateResolver, HttpSessionStateResolver>(); serviceCollection.AddTransient<IOverrideOptionsResolver, OverrideOptionsResolver>(); serviceCollection.AddSingleton<IRenderEngineOptionsResolver, CustomRenderEngineOptionResolver>(); serviceCollection.AddTransient<IHttpClientFactory, HttpClientFactory>(); }
-
以下のパッチで設定パッチを作成してください:
-
カスタムアセンブリと設定パッチをSitecoreインスタンスにデプロイしてください。
無視された経路にパスを追加します
一部の相関URLパスはヘッドレスサービスによって書き換えられません。デフォルトでは以下の通りです:
- -/media/
- ~/media/
- -/jssmedia/
- ~/jssmedia/
パスの追加または削除は型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverをオーバーライドすることで行えます。
無視されたパスにURLパスを追加するには:
-
nugetパッケージを参照Sitecore.JavaScriptServices.ViewEngine.Http。
-
型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを継承する型を作成します。
-
ResolveAllを上書きしてResolveForId。
-
基本メソッドで返されたLinkAttributeMapオプションフィールドを上書きします:
public override IEnumerable
ResolveAll(RenderEngineOptions runtimeOptions = null) { var optionsCollection = base.ResolveAll(runtimeOptions); foreach (var options in optionsCollection) { options.IgnoredPaths.Add("sitecore/shell/"); } return optionsCollection; }
public override HttpRenderEngineOptions ResolveForId(string id, RenderEngineOptions runtimeOptions = null) { var options = base.ResolveForId(id, runtimeOptions); options.IgnoredPaths.Add("sitecore/shell/"); return options; }
-
依存関係構成器を作成し、IRenderEngineOptionsResolverサービス登録をオーバーライドします:
public void Configure(IServiceCollection serviceCollection) { serviceCollection.AddTransient<IHttpRenderEngineFactory, HttpRenderEngineFactory>(); serviceCollection.AddTransient<IConfigurationReader, XmlConfigurationReader>(); serviceCollection.AddSingleton<IHttpSessionStateResolver, HttpSessionStateResolver>(); serviceCollection.AddTransient<IOverrideOptionsResolver, OverrideOptionsResolver>(); serviceCollection.AddSingleton<IRenderEngineOptionsResolver, CustomRenderEngineOptionResolver>(); serviceCollection.AddTransient<IHttpClientFactory, HttpClientFactory>(); }
-
以下のパッチで設定パッチを作成してください:
-
カスタムアセンブリと設定パッチをSitecoreインスタンスにデプロイしてください。