Skip to content

Instantly share code, notes, and snippets.

@sr-tamim
Last active September 27, 2023 11:37
Show Gist options
  • Save sr-tamim/6f2b561379414e5cd6ecbb4c4f5195b2 to your computer and use it in GitHub Desktop.
Save sr-tamim/6f2b561379414e5cd6ecbb4c4f5195b2 to your computer and use it in GitHub Desktop.
How to deploy ASP.NET MVC to server

Here's an elaboration of each step with necessary commands and sub-steps for updating and redeploying your ASP.NET MVC application on the server after making changes to the code on GitHub:

  1. Pull Latest Code from GitHub:

    • Open Git Bash or your preferred Git client on your local development machine.
    • Navigate to the directory where you want to clone the GitHub repository or where you have already cloned the repository.
    • Use the following command to pull the latest changes from GitHub:
      git pull origin master
      

    This command fetches and merges the latest changes from the master branch of your GitHub repository to your local working directory.

  2. Build and Test the Updated Code:

    • Open your ASP.NET MVC project in Visual Studio or your preferred IDE.
    • Build the solution to ensure there are no build errors:
      Build > Build Solution
      
    • Run unit tests and perform manual testing to verify that the changes work correctly.
  3. Create a Deployment Package:

    • Open a Command Prompt or PowerShell window on your local machine.
    • Navigate to the root directory of your ASP.NET MVC project.
    • Create a deployment package using the dotnet publish command:
      dotnet publish -c Release
      

    This command creates a deployment package in the bin/Release/netcoreappx.x/publish directory, where x.x corresponds to the .NET Core version.

  4. Stop the Current Application:

    • Log in to the server where your ASP.NET MVC application is hosted.
    • Open Internet Information Services (IIS) Manager.
    • In the left-hand panel, expand the "Sites" node and find your ASP.NET MVC application's site.
    • Right-click on the application's site and choose "Manage Web Site" > "Stop."
  5. Backup the Current Application (Optional but Recommended):

    • Create a backup of your application files and database (if applicable) on the server. This allows you to revert to the previous version if any issues arise during deployment.
  6. Deploy the Updated Code:

    • Use a file transfer method (e.g., FTP, SCP, or Rsync) to copy the deployment package or updated files to the appropriate directory on the server where your ASP.NET MVC application is hosted. Typically, this is the root directory or a virtual directory associated with the application in IIS.
  7. Start the Application:

    • Go back to Internet Information Services (IIS) Manager on the server.
    • Right-click on the application's site and choose "Manage Web Site" > "Start."
  8. Test the Updated Application:

    • After the application starts, open a web browser and navigate to your ASP.NET MVC application's URL to test it.
    • Thoroughly test all the features and functionalities to ensure they are working correctly.
  9. Monitor Server Logs (Optional):

    • Monitor server logs for any errors or warnings that may occur after the deployment.
    • Check the application's log files for any issues related to the new code changes.
  10. Communicate and Monitor:

    • Communicate with your team and stakeholders about the successful deployment.
    • Monitor the application's performance and user feedback to ensure there are no issues with the updated version.

Please note that the exact commands and steps may vary depending on your specific server environment, the hosting platform, and the build tools you are using. Adapt the steps to match your application's deployment process and ensure that you have appropriate permissions and backups in place before making any changes to the live server.


Regards

sr-tamim's Profilator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment