小問題一則。

為了測試Google登入整合,我將ASP.NET網站上傳Azure。經本機IIS Express測試無誤的網站,一掛到IIS下執行卻出現錯誤,在事件檢視器有以下訊息:

    • Unexpected error occurred while trying to access the LocalDB instance registry configuration. See the Windows Application event log for error details.
    • Windows API call SHGetKnownFolderPath returned error code: 5. Windows system error message is: Access is denied.
    • Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.

ASP.NET網站使用LocalDB存放使用者註冊、角色等資料,推測是無法正確載入資料庫出錯。訊息明確與Profile有關,IIS使用Application Pool處擬帳戶,而IIS Express使用開發者登入Windows的帳戶執行,推測為導致錯誤的關鍵。所幸訊息明確,馬上查到相關說明

LocalDB需要載入User Profile才能運作,而IIS Application Pool預設不會載入,故需手動修改C:\Windows\System32\inetsrv\config\applicationHost.config,找到<system.applicationHost><applicationPools>裡該AppPool對應設定,將loadUserProfile及setProfileEnvironment設為true:

<add name=“OAuthTest“ autoStart=“true“ managedRuntimeVersion=“v4.0“ managedPipelineMode=“Integrated“>
<processModel identityType=“ApplicationPoolIdentity“ loadUserProfile=“true“setProfileEnvironment=“true“ />
</add>

註:LocalDB主打輕巧簡便及與正式SQL行為相近,但由於運作範圍僅限單一應用程式,多用於開發測試,正式及中大型應用時還是會使用正規SQL Server。關於LocalDB,保哥有一篇詳細介紹可以參考。


Comments

Be the first to post a comment

Post a comment