2011-09-25 57 views
0

VS08-WIN7- VS08的ASP.NET開發Web服務器運行的是什麼帳戶?我正在嘗試寫入日誌文件。VS08-WIN7- ASP.NET Web服務器運行的帳戶是什麼?

protected void Page_Load(object sender, EventArgs e) 
{ 
    System.Diagnostics.Trace.WriteLineIf(lifecycleSwitch.TraceInfo, 
    string.Format("{0:yyyy-MM-dd HH:mm:ss.ffff}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", DateTime.Now, "Page", 
    this.GetType().Name, "Page_Load", "Start", User.Identity.Name, Thread.CurrentThread.ManagedThreadId, Request.Url.PathAndQuery, Session.SessionID)); 
    Response.Write(Environment.UserName); 
    System.Diagnostics.Trace.WriteLineIf(lifecycleSwitch.TraceInfo, 
    string.Format("{0:yyyy-MM-dd HH:mm:ss.ffff}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", DateTime.Now, "Page", 
    this.GetType().Name, "Page_Load", "Start", User.Identity.Name, Thread.CurrentThread.ManagedThreadId, Request.Url.PathAndQuery, Session.SessionID)); 
} 

但是,日誌文件一直顯示爲空。它是日誌文件所在文件夾的權限問題嗎?這是相應的web.config部分。

<system.diagnostics> 
<switches> 
    <add name="Lifecycle" value="4"/> 
</switches> 
<trace autoflush="false" indentsize="0"> 
    <listeners> 
    <add name="LifecycleLog" type="System.Diagnostics.TextWriterTraceListener" 
     initializeData="C:\Logs\lifecycle.log"/> 
    </listeners> 
</trace> 

+0

可以顯示在你的web.config跟蹤部分? –

+0

您正在使用哪個Web服務器?內置的Visual Studio開發服務器(Cassini)? IIS Express?或IIS 7.5(如果通過控制面板安裝IIS)? –

+0

內置VS08 dev web服務器(Cassisni)。 – dannyrosalex

回答

2

Web服務器以您的身份運行

+0

你的意思是System.Security.Principal.WindowsIdentity?因爲這是我在做Response.Write(Page.User.Identity)時得到的結果;這個東西是可分配給文件夾的寫入權限嗎? – dannyrosalex

+0

'Page.User.Identity'不是進程的身份,而是登錄用戶的身份(可以是相同的)。要獲得進程的身份,請使用'System.Threading.CurrentPrincipal.Identity.Name' –

相關問題