Stop azure azure function app programatically using C #

Sairam Ganji 46 Reputation points
2023-05-08T12:23:32.99+00:00

HI Team,

I am trying to stop my function app inside itself on certain conditions.
I landed to below page.

https://learn.microsoft.com/en-us/rest/api/appservice/web-apps/stop

Can you please elaborate how we can do below Security?
User's image

Is there any other way to stop function app?

I also read a function app can be disabled if "AzureWebJobs.disablefunction.Disabled" is set to true in Configuration Settings.
But issue here is I am not able to update "AzureWebJobs.disablefunction.Disabled" value in Configuration Settings through code in Function app.

Any inputs?

Thanks in advance,

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,605 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,971 Reputation points
    2023-05-09T05:15:37.5733333+00:00

    @Sairam Ganji Thanks for reaching out. To disable the function please refer to the disable function document.

    You can leverage the Azure REST API to programmatically stop your azure function and to know more about the Azure REST API, authentication etc. please refer to this document.

    You can also use the below REST endpoint to enable/disable a particular function
    PUT https://management.azure.com/subscriptions/{subscriptionID}/resourceGroups/{resourcegroupname}/providers/Microsoft.Web/sites/{sitename}/functions/{functionappname}/properties/state?api-version=2022-09-01
    content-type: application/json; charset=utf-8

    Request Body:

    {"properties":"disabled"}  
    

    OR

    {"properties":"enabled"}  
    

    Alternative you can also use this API to update app setting on your function app.

    In case if you want to do it for your local environment then you can define below in your local.settings.json but when you deploy to azure then you need to define it in Application setting of your function app.

    "AzureWebJobs.yourfunctionname.Disabled": true  
    

    OR

    "AzureWebJobs.yourfunctionname.Disabled": 1  
    

    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful