在建立網站之前,就是要把打包好的項目拷貝一份到IIS指定的路徑上,同時,還要為個別目錄設定相應的存取權限!
於是就產生了兩件事:
1。拷貝-》[這裡我是採用RAR打包,然後解壓]
2。設定許可權
如果是用拷貝方式,關於檔案夾Copy,可以參考我的這篇文章:
檔案夾複製操作(非遞迴迴圈遍曆檔案夾)
http://www.cnblogs.com/cyq1162/archive/2007/05/28/762294.html
為什麼我沒採用拷貝的方法,前提有兩個,就是項目的檔案夾有太多,在製作應用程式安裝程式時,只能添加檔案,而檔案夾只能一個一個的建立,太麻煩!要不就要把專案檔放到其它工程裡,那通過項目主輸出來實現。我也不想放到新工程或整合到工具項目裡,麻煩!
於是,我通過壓縮專案檔,當然沒有壓縮web.config,因為web.config是要修改的,在壓縮包裡就改不了。所以最後的做法是解壓RAR+檔案拷貝web.config!
關於RAR解壓,這裡給出一段代碼就算解決了:
RAR解壓
public bool WARToFoler(string rarFromPath, string rarToPath)
{
Process rarPro = new Process();
rarPro.StartInfo.FileName = AppConfig.SoftSetup_WinRARSystemPath;
rarPro.StartInfo.Arguments = string.Format(" x \"{0}\" \"{1}\" -o+ -r -ibck", rarFromPath, rarToPath);
rarPro.StartInfo.UseShellExecute = false;
rarPro.StartInfo.RedirectStandardInput = true;
rarPro.StartInfo.RedirectStandardOutput = true;
rarPro.StartInfo.RedirectStandardError = true;
rarPro.StartInfo.CreateNoWindow = true;
rarPro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
rarPro.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
rarPro.ErrorDataReceived += new DataReceivedEventHandler(rarPro_ErrorDataReceived);
rarPro.Start();//解壓開始
rarPro.BeginOutputReadLine();
rarPro.BeginErrorReadLine();
rarPro.WaitForExit();
rarPro.Dispose();
return IsOK;
}
void rarPro_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data!=null && e.Data != "")
{
outMsg.Text += "失敗:" + e.Data + "\r\n";
IsOK = false;
}
}
void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (e.Data != null && e.Data != "")
{
outMsg.Text+="成功:" + e.Data + "\r\n";
}
}
AppConfig.SoftSetup_WinRARSystemPath這個是就是安裝的RAR.exe路徑!
-ibck參數是讓解壓在後台運行,這樣可以不用彈出個解壓框!
前些天也寫過一篇和RAR相關的文章:
記錄下關於調用RAR解壓縮的問題
http://www.cnblogs.com/cyq1162/archive/2010/01/13/1646678.html
OK,RAR解壓就這麼告一段落,接下來,我有一個App_Data目錄,由於會往裡面寫產生的xml,所以為之添加一個可寫入權限!
設定許可權的方式有三種,一種用net內建的封裝類。另一種直接調用cacls.exe實現,還有一種就是網上下的調用Microsoft.win32的某種複雜方式。
以下就用第一種了。用net內建的類實現,非常的簡單,三行代碼:
設定許可權
System.Security.AccessControl.DirectorySecurity fSec = new DirectorySecurity();
fSec.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
System.IO.Directory.SetAccessControl(path, fSec);
這裡是添加了一個everyone使用者,當然也可以換成aspnet使用者,具體看安全性要求給了!後面就給出了所有許可權。
具體關於許可權的說明,多百google度或在vs下看按F1協助文檔就清楚了!
打完,收工!