How to host a site using command calling through C# code

Aparesh Dev 0 Reputation points
2023-08-02T07:36:16.24+00:00

I just wanted to automate the hosting process of my site. so can you please suggest if there are any set of command, by using this we can do the same.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,815 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,915 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 33,196 Reputation points Microsoft External Staff
    2023-08-03T02:11:58.59+00:00

    Hi @Aparesh Dev

    I just wanted to automate the hosting process of my site. so can you please suggest if there are any set of command, by using this we can do the same.

    Whether your site is an Asp.net core Application or not? If it is an Asp.net core application, you can use the following method:

    You can use the System.Diagnostics.Process class in C#, you can use this class to start the command-line process and runs the dotnet run command in the specified working directory (your Asp.net Core project root path), then it will host your site.

    Refer to the following sample: In the TestIdentity solution, there have a WebApplication3 project, I will use the following C# code (in a console project) to host the WebApplication3 project.

    using System.Diagnostics;
      
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C dotnet run";
    startInfo.WorkingDirectory = @"C:\Users\Administrator\source\repos\TestIdentity\WebApplication3";
    
    Process process = new Process();
    process.StartInfo = startInfo;
    process.Start();
    

    After that the result as below:

    User's image

    You can replace dotnet run with any other command that you want to run.

    Besides, if you want to deploy the application on the hosting server, see Host and deploy ASP.NET Core.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.