C# 調用VS內建程式WebDev.WebServer40.EXE 原始碼

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   使用   sp   

通過Process.Start啟動,VS內建程式WebDev.WebServer40.EXE

在內網架設網站時,為安裝IIS條件下用VS內建的小程式來測試效果非常不錯!

 

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net;using System.Net.NetworkInformation;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WebServer{    public partial class FormApp : Form    {        public FormApp()        {            InitializeComponent();        }        private void btnStart_Click(object sender, EventArgs e)        {            string _AppRoot = this.txtAppRoot.Text;            string _Port = this.txtPort.Text;            string _WebPath = this.txtWebPath.Text;            string _WebvPath = this.txtWebvPath.Text;            try            {                //簡單校正                CheckBoolTxt(_AppRoot, _Port, _WebPath, _WebvPath);                 string arguments = string.Format("/port:{0} /path:{1} /vpath:{2}", _Port, _WebPath, _WebvPath);                System.Diagnostics.Process.Start(_AppRoot, arguments);                this.linkLabel1.Text = string.Format("http://localhost:{0}{1}", _Port, _WebvPath);            }            catch (Exception ex)            {                MessageBox.Show(ex.Message, "提示:");            }        }        private void CheckBoolTxt(string _AppRoot, string _Port, string _WebPath, string _WebvPath)        {            if (!System.IO.File.Exists(_AppRoot))            {                throw new Exception("找不到指定程式!");            }            if (!System.Text.RegularExpressions.Regex.IsMatch(_Port, @"^(([1-6][0-5][0-5][0-3][0-5])|([1-9][0-9][0-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9])|([1-9]))$"))  //^[1-6]?[\d]{0,4}$            {                throw new Exception("連接埠:1-65535之間未使用的連接埠號碼!");            }            if (!System.IO.Directory.Exists(_WebPath))            {                throw new Exception("實體路徑不存在,請指定有效目錄!");            }            if (!_WebvPath.Contains("/"))            {                throw new Exception("虛擬目錄必須以‘/‘開頭!");            }            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();            IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();            int counts = ipEndPoints.Count<IPEndPoint>(o => o.Port == int.Parse(_Port));            if (counts > 0)            {                throw new Exception("連接埠已被佔用!");            }        }        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)        {            System.Diagnostics.Process.Start(this.linkLabel1.Text);        }    }}

C# 調用VS內建程式WebDev.WebServer40.EXE 原始碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.