网站安装打包 浏览网站[五] 附加IIS其它功能

在创建完网站与虚拟目录,接下来就是要浏览网站了,于是,在界面上多加一个按钮,点击浏览是顺势而加了:

代码就一句:

Process.Start("iexplore.exe"string.Format("http://{0}",txtWebsiteIP.Text));

 //IP地址用System.Net.Dns.GetHostAddresses(Dns.GetHostName())[0].ToString()就可获取


以下附加一下IIS一些其它功能:

IIS重启:

IIS重启
  public static bool ReStart(out string msg)
        {
            
try
            {
                msg 
= "";
                ServiceController iis 
= new ServiceController("iisadmin");
                
if (iis.Status == ServiceControllerStatus.Running)
                {
                    iis.Stop();
                }
                Process.Start(
"iisreset");//重启
                iis.Dispose();
                
return true;
            }
            
catch (Exception err)
            {
                msg 
= err.Message;
            }
            
return false;
        }

 IIS 开启:

IIS Start
 public static bool Start()
        {
            ServiceController iis 
= new ServiceController("iisadmin");
            
if (iis.Status == ServiceControllerStatus.Stopped)
            {
                iis.Start();
            }
            iis.Dispose();
            
return true;
        }

IIS 停止:

IIS Stop
public static bool Stop()
        {
            ServiceController iis 
= new ServiceController("iisadmin");
            
if (iis.Status == ServiceControllerStatus.Running)
            {
                iis.Stop();
            }
            iis.Dispose();
            
return true;
        }

注册asp.net:

aspnet 注册
 string aspnet_regiisPath=@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe";
            
if (!System.IO.File.Exists(aspnet_regiisPath))
            {
                aspnet_regiisPath 
= aspnet_regiisPath.Replace("C:""D:");
                
if (!System.IO.File.Exists(aspnet_regiisPath))
                {
                    aspnet_regiisPath 
= aspnet_regiisPath.Replace("D:""E:");
                    
if (!System.IO.File.Exists(aspnet_regiisPath))
                    {
                        MessageBox.Show(
"找不到Aspnet_regiis.exe的文件路径!");
                        
return;
                    }
                }
            }
            Process.Start(aspnet_regiisPath, 
"-i");

打完,收工!

版权声明:本文原创发表于 博客园,作者为 路过秋天 本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
个人微信公众号
创业QQ群:617713515
Donation(扫码支持作者):支付宝:
Donation(扫码支持作者):微信:
原文地址:https://www.cnblogs.com/cyq1162/p/1657346.html