我使用查询参数(路径)值在内容定义中构造加载 URI,如下所示:
<ContentDefinition Id="api.selfasserted.errorpage">
<LoadUri>https://{OAUTH-KV:path}/error.html</LoadUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.7</DataUri>
</ContentDefinition>
有没有办法为 LoadUri 中的查询参数设置默认值,以便在有人未在 URL 中传递任何查询参数时它不会失败?
不,您的 LoadUri 的域部分不可能有后备位置。
但是,您可以通过不同的方式构建它,通过参数化 URL 的路径部分来实现您想要实现的目标。
<LoadUri>https://{OAUTH-KV:path}/error.html</LoadUri>
会变成 <LoadUri>https://mytemplates.co.uk/{OAUTH-KV:brand}/error.html</LoadUri>
然后您将在您的网站/存储帐户上托管两个模板:
https://mytemplates.co.uk/LeosBrand/error.html
(如果提供了参数);https://mytemplates.co.uk/error.html
(如果没有参数,这将是后备)。
这并不能阻止人们给你一个错误的参数和不匹配的路径,但可以通过使用应用程序逻辑进行排序(这意味着与静态托管文件相比,应用程序服务)。
您还可以使用 ContentDefinitionParameters 将变量移动到查询参数 -
https://mytemplates.co.uk/error.html
的加载 URI 将请求位于 https://mytemplates.co.uk/error.html?brand=LeosBrand
的模板