<tfoot id='GKjfL'></tfoot>
    1. <legend id='GKjfL'><style id='GKjfL'><dir id='GKjfL'><q id='GKjfL'></q></dir></style></legend>

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

      1. <small id='GKjfL'></small><noframes id='GKjfL'>

          <bdo id='GKjfL'></bdo><ul id='GKjfL'></ul>

        FunctionsStartup vs IWebJobsStartup,在请求中读取 HttpHeaders 时出现问题

        时间:2023-10-05
      2. <tfoot id='q4FlY'></tfoot>
          <legend id='q4FlY'><style id='q4FlY'><dir id='q4FlY'><q id='q4FlY'></q></dir></style></legend>
          <i id='q4FlY'><tr id='q4FlY'><dt id='q4FlY'><q id='q4FlY'><span id='q4FlY'><b id='q4FlY'><form id='q4FlY'><ins id='q4FlY'></ins><ul id='q4FlY'></ul><sub id='q4FlY'></sub></form><legend id='q4FlY'></legend><bdo id='q4FlY'><pre id='q4FlY'><center id='q4FlY'></center></pre></bdo></b><th id='q4FlY'></th></span></q></dt></tr></i><div id='q4FlY'><tfoot id='q4FlY'></tfoot><dl id='q4FlY'><fieldset id='q4FlY'></fieldset></dl></div>

              <tbody id='q4FlY'></tbody>
              <bdo id='q4FlY'></bdo><ul id='q4FlY'></ul>

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

                1. 本文介绍了FunctionsStartup vs IWebJobsStartup,在请求中读取 HttpHeaders 时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在本地构建一个 .NET Core 3.1 Azure Functions 应用程序,并尝试配置一个启动类.当我实现一个从 FunctionsStartup 继承的类时,我无法将 .net core 3.1 类库导入我的项目.如果我这样做并尝试运行该应用程序,我会在执行窗口中收到以下错误:

                  I am building a .NET Core 3.1 Azure Functions application on my local and am trying to configure a startup class. When I implement a class to inherrit from FunctionsStartup I cannot import a .net core 3.1 class library into my project. If I do so and try to run the app, I get the following error in the execution window:

                  Microsoft.Azure.Functions.Extensions:找不到方法:Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Azure.WebJobs.Hosting.IWebJobsConfigurationBuilder.get_ConfigurationBuilder()'.值不能为空.(参数'提供者')

                  当我将 Startup 基类切换到 IWebJobsStartup 时,应用程序启动正常.当我提出请求并尝试单步执行代码时,我遇到了问题.我可以单步执行代码的初始部分(因此我知道我的请求已成功接收),但我无法单步执行我的某个函数.我收到下载提示,并且在 VS 工作区中打开一个页面,其中显示错误消息 TaskMethodInvker.cs not found 带有标记行 You need to find TaskMethodInvoker.cs 以查看源代码对于当前调用堆栈帧.下面的代码显示了我的功能:

                  When I switch the Startup base class to IWebJobsStartup the app starts fine. When I make a request and try stepping through the code I run into a problem. I can step through an initial portion of code (so I know my request is successfully received) but I am not able to step into one of my functions. I get a download prompt and a page opens up in the VS work area that has the error message TaskMethodInvker.cs not found with the tag line You need to find TaskMethodInvoker.cs to view the source for the current call stack frame. The below code shows my function:

                  [FunctionName("HttpAuth")]
                  public async Task<IActionResult> Run(
                      [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
                      ExecutionContext context,
                      ILogger log)
                  {
                      GetAzureADConfiguration(context);
                      var jwt = GetJwtFromHeader(req);
                  }
                  
                  private JwtSecurityToken GetSecurityToken(string encodedToken)
                  {
                      ...
                  }
                  
                  private string GetJwtFromHeader(HttpRequest req)
                  {
                      var authorizationHeader = req.Headers?["Authorization"];
                      string[] parts = authorizationHeader?.ToString().Split(null) ?? new string[0];
                      return (parts.Length == 2 && parts[0].Equals("Bearer")) ? parts[1] : string.Empty;
                  }
                  

                  GetAzureADConfiguration 函数正在执行,GetJwtFromHeader 未执行.似乎任何试图通过代码访问 Header 字典的函数都无法进入并导致我的错误.但是,如果我在监视窗口中检查对象,我会看到正确的值.

                  The GetAzureADConfiguration function is executing, GetJwtFromHeader is not. It seems that any function trying to access the Header dictionary via code can not be stepped into and causes my error. However, if I inspect the object in the watch window, I see the correct value.

                  这是我的 WebJobStartUp 代码:

                  Here is my WebJobStartUp code:

                  [assembly: WebJobsStartup(typeof(StartUp))]
                  namespace CriticalPath.Api.Functions
                  {
                      class StartUp : IWebJobsStartup 
                      {
                          public void Configure(IWebJobsBuilder builder) 
                          {
                              ...
                          }
                      }
                  }
                  

                  这是我尝试使用 FunctionsStartup 的方法

                  Here is what I tried with FunctionsStartup

                  [assembly: FunctionsStartup(typeof(Startup))]
                  namespace CriticalPath.Api.Functions
                  {
                      class StartUp : FunctionsStartup
                      {
                          public void Configure(IWebJobsBuilder builder)
                          {
                              ...
                          }
                      }
                  }
                  

                  为什么我不能单步执行引用请求标头的代码?FunctionsStartupIWebJobsStartup 有什么区别.如果我想使用 IWebJobsStartup,如何访问标题?

                  Why can't I step through my code that references the request's headers? What is the difference between FunctionsStartup and IWebJobsStartup. How do I access the headers if I want to use IWebJobsStartup?

                  推荐答案

                  我能够解决问题.这是逐个介绍:我的问题围绕着尝试导入一个类库而不是使用与我的 Azure Functions 应用程序冲突的依赖项.我是如何发现的:我创建了一个全新的 Azure Functions v3 项目和 .NET Core 3.1 库.经过一番试验后,我发现在我的 Startup 类中从 FunctionsStartup(不是 WebJobStartup)继承时,我能够成功导入一个空项目.在我的函数中,我添加了访问 req.Headers 字典中的条目的代码,这样我就可以看到函数何时运行失败.一旦我有一个空项目工作,我查看了一个没有正确导入的项目,并将非工作项目中的引用一一添加到我的空项目中.对于每个参考,我都测试了我的 Azure 函数,看看是什么破坏了它.当我到达 Microsoft.Extensions.Configuration v5.0 时,我的功能坏了.我将此依赖项降级为 v3.1.13 并且该功能有效.因此,在不起作用的项目中,我使用 Configuration 来访问我的秘密中的变量,版本肯定不匹配.解决这个问题.然后我想创建一个自定义属性.我切换到使用 WebJobStartup 并且 Web 触发器起作用了.

                  I was able to fix the problem. Here is the blow-by-blow: My problem revolved around trying to import a class library thant used a dependency that conflicted with my Azure Functions app. How I found this: I created a fresh Azure Functions v3 project and .NET Core 3.1 library. After experimenting with it a bit I found that while inherriting from FunctionsStartup (not WebJobStartup) in my Startup class, I was able to successfully import an empty project. In my function, I added code that accessed an entry from the req.Headers dictionary so I can see when running the function failed. Once I got an empty project working, I looked at a project that wasn't importing correctly and one by one added references in the non-working project to my empty project. With each reference I tested my Azure Function to see what breaks it. When I got to Microsoft.Extensions.Configuration v5.0, my function broke. I downgraded this dependency to v3.1.13 and the function worked. So in the project that didn't work I was using Configuration to access variables in my secrets there must have been a mismatch in versions. Fixing this worked. I then wanted to create a custom attribute. I switched over to using WebJobStartup and it the web trigger worked.

                  这篇关于FunctionsStartup vs IWebJobsStartup,在请求中读取 HttpHeaders 时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从 azure 函数连接到 MongoDB 下一篇:如何限制 C# 中的文本框只接收数字和(点“."或逗号“,"),在“."之后或“,&quo

                  相关文章

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

                    1. <legend id='0jn9G'><style id='0jn9G'><dir id='0jn9G'><q id='0jn9G'></q></dir></style></legend>

                    2. <small id='0jn9G'></small><noframes id='0jn9G'>

                        <bdo id='0jn9G'></bdo><ul id='0jn9G'></ul>
                      <tfoot id='0jn9G'></tfoot>