Azure-在对功能应用程序的每次请求之前执行一些代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Azure-在对功能应用程序的每次请求之前执行一些代码相关的知识,希望对你有一定的参考价值。

我创建了一个天蓝色函数应用程序,并在其中创建了几个函数。我想检查用户是否被授权访问路由(从我的数据库)。我需要在执行请求之前检查一下。如何在功能应用程序中实现此目标?

答案

如果您将函数v2与c#一起使用,则可以编写自己的Startup class并将其注册到函数中。 Startup class始终在函数执行之前执行。

这里是示例代码,请根据需要随时对其进行修改:

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;

[assembly: WebJobsStartup(typeof(FunctionApp16.MyStartup))]
namespace FunctionApp16
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run("your parameters")
        {
            //your code here
        }
    }

    public class MyStartup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            //write your code here, it will executes prior to the function method.
        }
    }

}

以上是关于Azure-在对功能应用程序的每次请求之前执行一些代码的主要内容,如果未能解决你的问题,请参考以下文章