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.

Developer technologies | ASP.NET | ASP.NET Core
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.