I have an azure web job created in Azure and configured to "On demand" schedule. I can run this web job from Azure Web Apps UI using "Run Once" button.

I have a provided hosted app and it has a page with a button. I want run the azure web job on the provided hosted app page button click. Is it possible?

If Yes, how do we call/invoke/run azure web job from a page in my provided hosted app?


This can be done using the WebJobs API. Assuming you want to call it from server side code:

public static async Task<HttpResponseMessage> InvokeWebJob()
        using (HttpClient httpClient = new HttpClient())
            httpClient.BaseAddress = new Uri("https://<azure site>.scm.azurewebsites.net/api/"); // replace with your site name
            var byteArray = Encoding.ASCII.GetBytes("username:key");    // you can get these details from your web job properties
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

            HttpResponseMessage responseMessage = null;
                responseMessage = await httpClient.PostAsync("triggeredwebjobs/<web job name>/run", null);
            catch (Exception ex)
                // logging etc.
            return responseMessage;

    this can be invoked like this and this will trigger your on-demand web job:

    var task = InvokeWebJob();
    // TODO: Check for null etc.
    var result = task.Result;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.