🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / web api swagger core iis kendi kendine durursa farket ve yeniden başlat

1-) C# RMOS - web api swagger core iis kendi kendine durursa farket ve yeniden başlat

 

açıklama : Programı yönetici olarak çalıştır veya sağ tık -> uyumluluk -> bu programı yönetici olarak çalıştıra tıkla

 

 

using Microsoft.Web.Administration;

using System;

using System.Linq;

using System.Windows.Forms;

namespace iisKontrol

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            try

            {

                using (ServerManager serverManager = new ServerManager())

                {

                    Site site = serverManager.Sites["rmossepetv2"]; // IIS'te hedeflenen site adı

                    var uygulamaHavuzlari = serverManager.ApplicationPools.ToList();

                    if (site != null)

                    {

                        // Durdurma

                        if (site.State == ObjectState.Stopped)

                        {

                            site.Start();

                            MessageBox.Show("İSS BAŞLATILDI");

                        }

                        else

                        {

                            site.Stop();

                            MessageBox.Show("İSS DURDURULDU");

                        }

                    }

                    else

                    {

                        MessageBox.Show("Belirtilen site bulunamadı.");

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show($"{ex}");

            }

        }

 

    }

}

 

 

 

2- mssql durursa yeniden başlatma

using Microsoft.Web.Administration;

using System;

using System.Linq;

using System.ServiceProcess;

using System.Windows.Forms;

namespace iisKontrol

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            try

            {

                string serviceName = "MSSQLSERVER"; // SQL Server hizmet adı

                ServiceController sqlService = new ServiceController(serviceName);

                if (sqlService.Status == ServiceControllerStatus.Stopped)

                {

                    sqlService.Start();

                    sqlService.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30));

                    Console.WriteLine("SQL Server başlatıldı.");

 

                }

    }

}

}

 

 

 2023 Kasım 25 Cumartesi
 211