If you use GitHub to manage the source code of your website, you can utilize webhooks to transmit GitHub events to third-party services. In this article, we will explore how to deploy a website to IIS, as well as how to pull the source code and automatically update the site when a push event occurs.
IIS Configuration in Windows 10
To activate IIS, go to the "Windows features" menu. By default, all "Application Development Features" are turned off. Choose the necessary features.
How to Use Visual C# to Handle HTTP Request
In Visual Studio, create an empty ASP.NET web application.
Create an HTML file called index.htm.
Webhook.ashx should have a generic handler.
Publish the project.
Select IIS > File System.
To add the website, launch IIS.
To see if the URL works in your web browser, go to http://localhost/Webhook.ashx.
The following step is to execute the git pull command in C#. We can refer to the CodeProject sample code.
A batch file to execute required commands.:
batchFile = Path.Combine(context.Server.MapPath("."), "github.bat");
objThread.Start(batchFile);
The physical path of the project is d:\iis, so the github.bat is as follows:
d:
cd d:\\iis
git pull
How to Expose the Local Web Server to the Internet
We must give a proper URL to use GitHub webhooks. Ngrok is an excellent tool for connecting a local webserver to the internet.
ngrok http 80
The webhook URL is now https://048dab0c.ngrok.io/Webhook.ashx.
How to Use GitHub Webhook to Trigger the Auto-Deployment
Once the URL is complete, we may create a new GitHub repository.
Add d:\iis
to the remote repository and push it.
To add the payload URL, go to Settings > Webhooks and enter
:
Clone the repository to a new location or another computer. Make some changes to the index.html file and commit them to GitHub.
The web server will immediately receive an HTTP request and execute the 'git pull' operation.
To see the update, refresh the website https://048dab0c.ngrok.io/.
Top comments (0)