Power Shell or .Net library to check if HTTPS is setup for a domain

john john 1,026 Reputation points
2022-05-29T01:30:44.693+00:00

I am building ASP.NET core MVC web application which allow users to enter a domain name and click submit >> then the application should check if HTTPS is setup for a domain >> update the backend accordingly. So my question is; If there is there a .NET core library which allow us to check if HTTPS is setup for a domain? Or can we use Power shell and get the results of it inside our ASP.NET core web application?

Thanks

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

1 answer

Sort by: Most helpful
  1. Limitless Technology 40,046 Reputation points
    2022-06-06T07:51:56.2+00:00

    Hello Johnjohn,

    Yes, you can run Powershell from ASP.NET code, for your confort.

    For example:

    using System.Management.Automation;
    using System.Management.Automation.Runspaces;
    using Microsoft.PowerShell;

    var initialSessionState = InitialSessionState.CreateDefault();
    initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
    using (PowerShell powerShell = PowerShell.Create(initialSessionState))
    {
    powerShell.AddCommand("whoami");
    foreach (var item in powerShell.Invoke())
    {
    Console.WriteLine(item.BaseObject.ToString());
    }
    if (powerShell.HadErrors)
    {
    throw new Exception("powershell script had errors");
    }
    }


    --If the reply is helpful, please Upvote and Accept as answer--

    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.