標籤: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 原始碼