文章編號: 908158 - 上次校閱: 2007年12月3日 - 版次: 1.2

當 ASP.NET 2.0 設定成以使用者帳戶執行時,出現錯誤訊息: 「 無法產生暫時類別 」

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

徵狀

考慮下列案例:
  • 您建立 Microsoft ASP.NET 2.0 應用程式。
  • ASP.NET 2.0 設定為以使用者帳戶執行。
  • 在 ASP.NET 2.0 設定檔 屬性的 [SerializeAs 屬性設定,以 XML
在這種情況下 ASP.NET 2.0 可能不會儲存該使用者設定檔,而且可能會收到類似下列的錯誤訊息:
[InvalidOperationException: 無法產生暫時類別 (結果 = 1)。
錯誤 CS2001: 找不到 'D:\WINDOWS\TEMP\d0lurtzx.0.cs' 的來源檔案
錯誤 CS2008: 沒有指定的輸入

發生的原因

如果使用者帳戶不具有清單資料夾內容 」 與 「 讀取 」 權限 %windir%\Temp 資料夾上,就會發生這個問題。

解決方案

如果要解決這個問題,授予使用者帳戶清單] 中 %windir%\Temp 資料夾資料夾內容] 及 [讀取權限。

其他相關資訊

如果要重現問題的步驟

  1. 建立網站在 [Microsoft 網際網路資訊服務 (IIS) 管理員。
  2. 建立本機的 Microsoft Windows NT 使用者帳戶。
  3. 按一下 [開始],再按一下 [執行]、 輸入 cmd,] 然後再按一下 [確定]
  4. 在命令提示字元下輸入下列命令:
    cd Path
    附註Path 代表電腦上的 [Microsoft.NET Framework 2.0] 資料夾的路徑。
  5. 在命令提示字元中,請輸入下列指令,並按下 ENTER:
    aspnet_regiis-ga User
    附註User 代表您在步驟 2 中建立使用者帳戶。
  6. 變更您在步驟 1 至您在步驟 2 中建立的帳戶所建立的網站的應用程式集區識別。
  7. 按一下 [開始],再按一下 [執行]、 輸入 cmd,] 然後再按一下 [確定]
  8. 在命令提示字元下鍵入 iisreset /restart,並按下 ENTER。
  9. 建立 Web.config 檔,然後再新增下列程式碼範例至 Web.config 檔。

    附註<Server> 代表伺服器名稱 <User> 代表使用者] 名稱 <Password> 代表使用者,及 <Catalog> represents the catalog name.
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <customErrors mode="Off" />
        <profile defaultProvider="SqlPProvider" enabled="true">
          <providers>
            <add name="SqlPProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=1.2.3400.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="SqlPProviderConnection" />
          </providers>
          <properties>
            <add name="FavoriteURLs" type="System.Collections.Specialized.StringCollection" readOnly="false" serializeAs="Xml" />
          </properties>
        </profile>
        <anonymousIdentification enabled="true" cookieless="UseDeviceProfile" />
        <authentication mode="Forms">
          <forms>
            <credentials passwordFormat="Clear">
              <user name="a" password="a" />
            </credentials>
          </forms>
        </authentication>
        <authorization>
          <deny users="?" />
        </authorization>
      </system.web>
      <connectionStrings>
        <add name="SqlPProviderConnection" connectionString="server=<Server> ;UID=<User>;PWD=<Password>;Initial Catalog=<Catalog>" />
      </connectionStrings>
    </configuration>
  10. 建立名為 Login.aspx 的檔案,然後再新增下列程式碼範例到 Login.aspx file.
    <%@ Page LANGUAGE="cs" %>
    <form runat=server>
    	<asp:literal runat=server id="MyText" Text=""></asp:literal>
    	<asp:TextBox runat=server id="UsernameTextBox" Text="Type a user name"></asp:TextBox>
    	<asp:TextBox runat=server id="PasswordTextBox" Text="Type a password"></asp:TextBox>
    	<asp:Button id="Submit"  Text="Submit" runat="server"/>
    </form>
    <script runat="server" >
    protected void Page_Load(Object source, EventArgs e)
      {
    	
    	MyText.Text += "[Login Page: you are not authenticated]<br>";
          String strUserName  = UsernameTextBox.Text;
          String strPassword  = PasswordTextBox.Text;
    
          bool   fPersist     = false;
          bool   fVerifed     = System.Web.Security.FormsAuthentication.Authenticate(strUserName, strPassword);
          if( fVerifed)
          {
              System.Web.Security.FormsAuthentication.RedirectFromLoginPage(strUserName, fPersist);
          }
      }
    
    </script>
  11. Create a file that is named Test.aspx, and then add the following code example to the Test.aspx file.
    <%@ Page LANGUAGE="cs" Debug="true" %>
    <form runat="server">
    	<asp:Literal runat="server" id="Literal1" Text=""></asp:literal>
    	<asp:Button text="Signout" OnClick="Signout_Click" id="SignOutButton" runat=server/>
    </form>
    <script runat="server" >
    void Page_Load(object sender, EventArgs e) 
    {
    
    	Literal1.Text += "[User.Identity.Name=" + User.Identity.Name +"]<br>";
    	Profile.FavoriteURLs = new System.Collections.Specialized.StringCollection();
    	Profile.FavoriteURLs.Add("MyString1");
    	Profile.FavoriteURLs.Add("MyString2");
    	Profile.FavoriteURLs.Add("MyString3");
    
    
    	if (Profile.FavoriteURLs != null) {
    		for (int i=0; i<Profile.FavoriteURLs.Count; i++) {
    			Literal1.Text += "[FavoriteURLs=" + Profile.FavoriteURLs[i] + "]<br>";
    		}
    	}
    	
    }
    
    
    void Signout_Click(Object sender, EventArgs E) {  
        System.Web.Security.FormsAuthentication.SignOut();
        Response.Redirect(System.Web.Security.FormsAuthentication.LoginUrl);
    }
    </script>
  12. 要求 Test.aspx。

這篇文章中的資訊適用於:
  • Microsoft .NET Framework 2.0
關鍵字:?
kbmt kbtshoot kberrmsg kbcode kbprb KB908158 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:908158? (http://support.microsoft.com/kb/908158/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。