我也跟着下面的文章:Appcmd.exe的無法讀取配置文件,由於權限不足
Cannot read configuration file due to insufficient permissions
我也嘗試手動設置權相關文件,但我不能讓sucess spely。在appcmd.exe文件上。
我試圖更新applicationHost.config文件來動態設置IIS重置時間,當我的網站加載在IIS上。爲此,我試圖在我的項目的global.asax文件中執行以下代碼。
以下是代碼:
string WindowsDir = Server.MapPath("~/Startup");
string command = WindowsDir + @"\Startup.cmd";
string outputFilePath = WindowsDir + @"\log.txt";
string arguments = String.Format("/c echo Startup task (Startup.cmd) executed at {0} >>\"{1}\"", System.DateTime.UtcNow.ToString(), outputFilePath);
//System.Diagnostics.Process.Start(command, arguments);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = command;
startInfo.Arguments = arguments;
process.StartInfo = startInfo;
process.Start();
這工作完全當我運行我在Visual Studio中的網站。但是當我將它部署IIS它會產生以下錯誤:
錯誤:
c:\windows\system32\inetsrv>REM *** Prevent the IIS app pools from shutting down due to being idle.
c:\windows\system32\inetsrv>C:\Windows\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00 /commit:apphost
ERROR (message:Configuration error
Filename: redirection.config
Line Number: 0
Description: Cannot read configuration file due to insufficient permissions.)
c:\windows\system32\inetsrv>REM *** Schedule IIS app pool recycles for 8:00 AM UTC time (1:00 AM MST)
c:\windows\system32\inetsrv>C:\Windows\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.schedule.[value='08:00:00']" /commit:apphost
ERROR (message:Configuration error Filename: redirection.config
Line Number: 0
Description: Cannot read configuration file due to insufficient permissions.)
c:\windows\system32\inetsrv>REM *** Prevent IIS app pool recycles from recycling on the default schedule of 1740 minutes (29 hours).
c:\windows\system32\inetsrv>C:\Windows\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.time:00:00:00 /commit:apphost
ERROR (message:Configuration error
Filename: redirection.config
Line Number: 0
Description: Cannot read configuration file due to insufficient permissions.)
然後我試圖執行以下代碼:
string WindowsDir = Server.MapPath("~/Startup");
string command = WindowsDir + @"\Startup.cmd";
string outputFilePath = WindowsDir + @"\log.txt";
string arguments = String.Format("/c echo Startup task (Startup.cmd) executed at {0} >>\"{1}\"", System.DateTime.UtcNow.ToString(), outputFilePath);
//System.Diagnostics.Process.Start(command, arguments);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = command;
startInfo.Arguments = arguments;
string name = "Administrator";
string pass = "password";
startInfo.Password = pass.Aggregate(new System.Security.SecureString(), (ss, c) => { ss.AppendChar(c); return ss; });
startInfo.UserName = name;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
process.StartInfo = startInfo;
process.Start();
那麼它並沒有從Visual Studio甚至工作,然後我恢復到在Visual Studio中工作的代碼(如上所述)。而在Web.config文件(內標籤)添加以下標籤:
<authentication mode="Windows"/>
<identity impersonate="true" userName="Administrator" password="password"/>
但是,當我跑IIS網站(7.5),沒有工作。
任何想法如何使這項工作在IIS(7.5)?
感謝