<i id='lhNli'><tr id='lhNli'><dt id='lhNli'><q id='lhNli'><span id='lhNli'><b id='lhNli'><form id='lhNli'><ins id='lhNli'></ins><ul id='lhNli'></ul><sub id='lhNli'></sub></form><legend id='lhNli'></legend><bdo id='lhNli'><pre id='lhNli'><center id='lhNli'></center></pre></bdo></b><th id='lhNli'></th></span></q></dt></tr></i><div id='lhNli'><tfoot id='lhNli'></tfoot><dl id='lhNli'><fieldset id='lhNli'></fieldset></dl></div>

    <legend id='lhNli'><style id='lhNli'><dir id='lhNli'><q id='lhNli'></q></dir></style></legend>

        • <bdo id='lhNli'></bdo><ul id='lhNli'></ul>
        <tfoot id='lhNli'></tfoot>

        <small id='lhNli'></small><noframes id='lhNli'>

      1. 如何在 Azure Function 的自定义 HTTP 路由中指定查询参数?

        How to specify a query parameter in a custom HTTP route of an Azure Function?(如何在 Azure Function 的自定义 HTTP 路由中指定查询参数?)
          <tbody id='3YuzS'></tbody>

            1. <legend id='3YuzS'><style id='3YuzS'><dir id='3YuzS'><q id='3YuzS'></q></dir></style></legend>

              <tfoot id='3YuzS'></tfoot>
                <i id='3YuzS'><tr id='3YuzS'><dt id='3YuzS'><q id='3YuzS'><span id='3YuzS'><b id='3YuzS'><form id='3YuzS'><ins id='3YuzS'></ins><ul id='3YuzS'></ul><sub id='3YuzS'></sub></form><legend id='3YuzS'></legend><bdo id='3YuzS'><pre id='3YuzS'><center id='3YuzS'></center></pre></bdo></b><th id='3YuzS'></th></span></q></dt></tr></i><div id='3YuzS'><tfoot id='3YuzS'></tfoot><dl id='3YuzS'><fieldset id='3YuzS'></fieldset></dl></div>

                <small id='3YuzS'></small><noframes id='3YuzS'>

                  <bdo id='3YuzS'></bdo><ul id='3YuzS'></ul>

                  本文介绍了如何在 Azure Function 的自定义 HTTP 路由中指定查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Azure 函数,我想设置一个自定义 HTTP 端点.在回答这个 SO 问题,我最终得到了这样的结果:

                  I have an Azure Function and I want to set a custom HTTP endpoint. Following the answer to this SO question, I ended up with something like this:

                  [FunctionName("DoSomething")]
                  public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}")]
                                  HttpRequest request, ILogger logger, string tenantId, string locationId, string manufacturer)
                  {
                          // 
                  }
                  

                  但是,该路由不被 Webjob 接受:

                  However, the route is not accepted by the Webjob:

                  "v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}"
                  

                  原因是因为问号'?':

                  The reason is because of the question mark '?':

                  创建名为DoSomething"的路由时出错,并且模板'api/v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}'.文字部分 'products?manufacturer=' 无效.文字部分不能包含?"特点.参数名称:routeTemplate文字部分 'products?manufacturer=' 无效.文字部分不能包含?"字符.

                  An error occurred while creating the route with name 'DoSomething' and template 'api/v1/tenants/{tenantId}/locations/{locationId}/products?manufacturer={manufacturer}'. The literal section 'products?manufacturer=' is invalid. Literal sections cannot contain the '?' character. Parameter name: routeTemplate The literal section 'products?manufacturer=' is invalid. Literal sections cannot contain the '?' character.

                  问题

                  如何在 Azure Function 的自定义 HTTP 端点中指定查询参数?

                  How can I specify a query parameter in a custom HTTP endpoint of my Azure Function?

                  推荐答案

                  恐怕不能把查询参数放到Route里.

                  I am afraid it's not possible to put query parameter in Route.

                  Microsoft.AspNetCore.Routing:文字部分 'products?manufacturer=' 无效.文字部分不能包含?"字符.

                  Microsoft.AspNetCore.Routing: The literal section 'products?manufacturer=' is invalid. Literal sections cannot contain the '?' character.

                  它是 ASP.NET Routing 的内置限制,Azure Function 使用它来构建 Http 触发器的路由.

                  It's a built-in restriction of ASP.NET Routing, which is used by Azure Function to build route for Http trigger.

                  允许我将值作为 Run 的方法参数之一获取,而不是戳到 HttpRequest 实例

                  allow me to get the value as one of the Run's method parameters instead of poking at the HttpRequest instance

                  如果是你想在路由中放入查询参数的原因,我建议你添加 IDictionary<string, string>在方法签名中查询,并使用query["manufacturer"] 来访问函数代码中的参数.但老实说,它与 request.Query["manufacturer"] 几乎相同.

                  If it's the reason why you want to put query parameter in route, I would suggest you add IDictionary<string, string> query in method signature and use query["manufacturer"] to access the parameter in function code. But honestly it's almost the same as request.Query["manufacturer"].

                  或者您可能必须遵循建议,将查询参数转换为 products/{productId} 之类的路由.

                  Or you may have to follow the recommendation, transform the query parameter to route like products/{productId}.

                  这篇关于如何在 Azure Function 的自定义 HTTP 路由中指定查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  • <tfoot id='19dNr'></tfoot>

                        <tbody id='19dNr'></tbody>

                      <small id='19dNr'></small><noframes id='19dNr'>

                        <bdo id='19dNr'></bdo><ul id='19dNr'></ul>

                            <legend id='19dNr'><style id='19dNr'><dir id='19dNr'><q id='19dNr'></q></dir></style></legend>
                          1. <i id='19dNr'><tr id='19dNr'><dt id='19dNr'><q id='19dNr'><span id='19dNr'><b id='19dNr'><form id='19dNr'><ins id='19dNr'></ins><ul id='19dNr'></ul><sub id='19dNr'></sub></form><legend id='19dNr'></legend><bdo id='19dNr'><pre id='19dNr'><center id='19dNr'></center></pre></bdo></b><th id='19dNr'></th></span></q></dt></tr></i><div id='19dNr'><tfoot id='19dNr'></tfoot><dl id='19dNr'><fieldset id='19dNr'></fieldset></dl></div>