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

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

代码就一句:

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

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


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

IIS重启:

05233808_FzsH.gif 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 开启:

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

IIS 停止:

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

注册asp.net:

05233808_FzsH.gif 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 " );

打完,收工!

转载于:https://my.oschina.net/secyaher/blog/274376

猜你喜欢

转载自blog.csdn.net/weixin_34119545/article/details/91966699