2

是否有任何簡單的診斷可以運行以確定爲什麼身份驗證不與ClientFormsAuthenticationMembershipProvider提供程序一起工作?我的問題:我的Membership ValidateUser請求有什麼問題? (使用ClientFormsAuthenticationMembershipProvider)

我有一個網站(我們稱之爲「身份驗證器」網站)在服務器A上託管,該服務器配置爲使用AspNetSqlMembershipProvider提供程序進行成員資格和角色管理。該網站的(我認爲是)相關的web.config鍵是這些:

<membership> 
     <providers> 
      <clear /> 
      <add name="AspNetSqlMembershipProvider" 
       type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
       connectionStringName="MMMS35.API" 
       enablePasswordRetrieval="false" 
       enablePasswordReset="true" 
       requiresQuestionAndAnswer="false" 
       applicationName="Moose" 
       requiresUniqueEmail="false" 
       passwordFormat="Hashed" 
       maxInvalidPasswordAttempts="5" 
       minRequiredPasswordLength="7" 
       minRequiredNonalphanumericCharacters="0" 
       passwordAttemptWindow="1" 
       passwordStrengthRegularExpression="" /> 
     </providers> 
    </membership> 
    <profile> 
     <providers> 
      <clear /> 
      <add name="AspNetSqlProfileProvider" 
       connectionStringName="MMMS35.API" 
       applicationName="Moose" 
       type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 
     </providers> 
    </profile> 
    <roleManager enabled="true"> 
     <providers> 
      <clear /> 
      <add name="AspNetSqlRoleProvider" 
       connectionStringName="MMMS35.API" 
       applicationName="Moose" 
       type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 
     </providers> 
    </roleManager> 

我有另一個網站(稱爲「測試客戶端」網站)託管在服務器B在同一網絡上的服務器A,但是我確實知道服務器A & B之間的網絡路徑,路由器配置等等。測試客戶端具有模擬登錄設置,該設置使用ClientFormsAuthenticationMembershipProvider提供者來請求「認證者」網站進行認證測試客戶端上給出的憑證。測試客戶端的相關的web.config部分是這些:

<membership defaultProvider="ClientAuthenticationMembershipProvider"> 
     <providers> 
      <clear/> 
      <add name="ClientAuthenticationMembershipProvider" 
       type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       serviceUri="http://slmooseapp1/mia/Authentication_JSON_AppService.axd" 
       credentialsProvider="" 
       savePasswordHashLocally="False"/> 
     </providers> 
    </membership> 
    <roleManager defaultProvider="ClientRoleProvider" enabled="true"> 
     <providers> 
      <clear/> 
      <add name="ClientRoleProvider" 
       type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       serviceUri="http://slmooseapp1/mia/Role_JSON_AppService.axd" 
       cacheTimeout="1"/> 
     </providers> 
    </roleManager> 

當測試客戶端執行這一行:

DirectCast(Membership.Provider, ClientServices.Providers.ClientFormsAuthenticationMembershipProvider).ValidateUser(UserName.Text, Password.Text) 

我得到一個異常:

System.UnauthorizedAccessException: Access to the path 'C:\Documents and Settings\Default User\Application Data\Microsoft Corporation\Internet Information Services\6.0.3790.3959' is denied. 

然而,當我使用完全相同的web.config serviceUri路徑(即,我的客戶端成員資格提供程序指向服務器A上的相同身份驗證網站)在我的開發框(而不是服務器B上)上運行測試客戶端,驗證用戶和獲得該用戶的角色完美地工作。

如果我打開服務器B上的瀏覽器,並從身份驗證的網站請求頁面時,驗證Web應用程序運行正常,所以我知道我可以從服務器B的HTTP請求到服務器A成功。當ClientFormsAuthenticationMembershipProvider嘗試創建(我認爲是)從服務器B到服務器A的JSON請求時,會發生什麼情況?

EDIT(9/21/2009):

現在我已經試過這種情況下與身份驗證的網站,並在同一臺測試客戶端(這是不是我的開發機)。它仍然失敗。我寫編程原始HTTP請求並沒有得到成功的響應...

請求:

Content-Type: application/json 
Host: slappdev 
Content-Length: 70 
Expect: 100-continue 
Connection: Keep-Alive 

{"userName":"mdh","password":"test123","createPersistentCookie":false} 

響應:

MicrosoftOfficeWebServer: 5.0_Pub 
Content-Length: 10 
Cache-Control: private, max-age=0 
Content-Type: application/json; charset=utf-8 
Date: Mon, 21 Sep 2009 20:10:13 GMT 
Set-Cookie: AppName=1756811D52C4619AC78...; path=/; HttpOnly 
Server: Microsoft-IIS/6.0 
X-AspNet-Version: 2.0.50727 
X-Powered-By: ASP.NET 

{"d":true} 

所以,我的猜測是,什麼是錯的,通過工作時.Net框架調用從ValidateUser獲取實際的HTTP請求。有任何想法嗎?

編輯(2009/9/22)

引發的異常被拋出時,我的測試客戶端的網頁試圖訪問System.Windows.Forms.Application.UserAppDataPath作爲完全相同的例外。將connectionStringName屬性添加到指向客戶端Web應用程序的web.config文件中的有效連接字符串名稱的membership/providers/add鍵會更改異常!

System.Data.SqlClient.SqlException: Invalid object name 'ApplicationProperties'. at System.Data.SqlClient.SqlConnection.OnError 

因此,如果所有的成員函數都使用serviceUri,爲什麼在客戶端本地嘗試了任何東西?而且,我需要運行哪些實用程序來將這些新的表/對象添加到我的數據庫中以支持客戶端成員資格提供程序?

回答

2

的ClientAuthenticationMembershipProvider具有離線緩存功能。如果無法訪問實際的成員資格提供程序,則客戶端成員資格提供程序可以在客戶端計算機上緩存憑據並使用這些脫機憑據。此脫機緩存由自動生成並存儲在System.Windows.Forms.Application.UserAppDataPath位置中的SQL Server Compact Edition數據庫文件表示。

根據this MSDN article,您可以配置本地脫機緩存以使用數據庫。您必須手動創建文章中指定的數據庫表(在我的9/22編輯中,我還沒有創建這些表,並且沒有實用工具可以這樣做)。我這樣做了,但客戶仍希望在本地機器上爲本地SQL CE文件創建文件夾結構,即使它永遠不會創建這樣的文件。除了我的本地工作站之外,對於我測試的每臺計算機,IIS用戶都無權訪問爲本地緩存數據庫生成該文件夾結構,該數據庫生成UnauthorizedAccessException。

我很不滿意A)沒有配置鍵來關閉成員資格的脫機緩存,B)即使將脫機緩存指向數據庫時,客戶端成員資格提供程序仍然必須生成一個文件夾路徑它永遠不會創建的本地緩存文件。

0

如果您將system.diagnostic標記添加到您的web.config文件中,它將起作用。 (我來到這裏只有一個空文件,但還沒有一個錯誤信息。)

<system.diagnostics> 
     <sources> 
      <!-- This section defines the logging configuration for My.Application.Log --> 
      <source name="DefaultSource" switchName="DefaultSwitch"> 
       <listeners> 
        <add name="myListener"/> 
        <!-- Uncomment the below section to write to the Application Event Log --> 
        <!--<add name="EventLog"/>--> 
       </listeners> 
      </source> 
     </sources> 
     <switches> 
      <add name="DefaultSwitch" value="Information" /> 
     </switches> 
     <sharedListeners> 
      <add name="myListener" 
         type="System.Diagnostics.TextWriterTraceListener" 
         initializeData="c:\temp\MyFile.log" /> 
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> 
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> --> 
     </sharedListeners> 
    </system.diagnostics> 
+0

非常好 - 我會試試看。謝謝。 – 2009-09-16 15:32:49

+0

我已將此web.config節點添加到身份驗證服務器應用程序和測試應用程序。我也打開了事件日誌。沒有消息出現在事件日誌中,並且在C:\ temp中沒有創建任何文件。 – 2009-09-21 20:03:17