1

我在 WCF 服务后面有以下代码:

if (Sitecore.Security.Authentication.AuthenticationManager.Login("sitecore\\" + username, password, false)) 
{ 
  // do something 
} 

但我得到一个“对象未设置”异常,具有以下堆栈跟踪:

at System.Web.Profile.SqlProfileProvider.GetPropertyValuesFromDatabase(String userName, SettingsPropertyValueCollection svc) 
at System.Web.Profile.SqlProfileProvider.GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider) 
at System.Configuration.SettingsBase.SetPropertyValueByName(String propertyName, Object propertyValue) 
at System.Configuration.SettingsBase.set_Item(String propertyName, Object value) 
at System.Web.Profile.ProfileBase.SetInternal(String propertyName, Object value) 
at System.Web.Profile.ProfileBase.set_Item(String propertyName, Object value) 
at System.Web.Profile.ProfileBase.SetPropertyValue(String propertyName, Object propertyValue) 
at Sitecore.Security.UserProfile.SetPropertyValueCore(String propertyName, Object value) 
at Sitecore.Security.UserProfile.set_SerializedData(Object value) 
at Sitecore.Security.UserProfile.get_CustomProperties() 
at Sitecore.Security.UserProfile.GetCustomProperty(String propertyName) 
at Sitecore.Security.SecurityUtil.GetUserDigestCredentials(User user, Boolean withoutDomain) 
at Sitecore.Security.SecurityUtil.UpdateDigestCredentials(String username, String password) 
at Sitecore.Security.SitecoreMembershipProvider.ValidateUser(String username, String password) 
at System.Web.Security.Membership.ValidateUser(String username, String password) 
at Sitecore.Security.Authentication.AuthenticationHelper.ValidateUser(String userName, String password) 
at Sitecore.Security.Authentication.MembershipAuthenticationProvider.Login(String userName, String password, Boolean persistent) 
at Sitecore.Security.Authentication.AuthenticationManager.Login(String userName, String password, Boolean persistent) 
at BaillieGifford.Code.services.DR.LoginToSiteCore(String username, String password) in c:\Dev\Development-Websites\Mainwebsite2012-DR\Code\services\DR.svc.cs:line 26 
at SyncInvokeLoginToSiteCore(Object , Object[] , Object[] ) 
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 

堆栈跟踪似乎表明用户的属性存在问题(某处),但并没有准确说明什么...

有什么想法吗?

更新:

来自 web.config 的配置文件位:

<profile defaultProvider="sql" enabled="true" inherits="Sitecore.Security.UserProfile, Sitecore.Kernel">
<providers>
<clear/>
<add name="sql" type="System.Web.Profile.SqlProfileProvider" connectionStringName="core" applicationName="sitecore"/>
<add name="switcher" type="Sitecore.Security.SwitchingProfileProvider, Sitecore.Kernel" applicationName="sitecore" mappings="switchingProviders/profile"/>
</providers>
<properties>
<clear/>
<add type="System.String" name="SC_UserData"/>
</properties>
</profile>
4

1 回答 1

2

当您使用自定义配置文件提供程序并且未将其设置为默认提供程序时,可能会发生此异常。检查是否在 web.config 中设置了 defaultProvider:

<profile defaultProvider="CustomizedProfileProvider"> <-- CHECK IF DEFAULT PROVIDER IS SET

  <providers>

    <clear/>

    <add name="CustomizedProfileProvider" type="System.Web.Profile.SqlProfileProvider"

         connectionStringName="database"

         applicationName="/app"/>

  </providers>

</profile>

此外,该方法System.Web.Profile.SqlProfileProvider.GetPropertyValuesFromDatabase需要HttpContext.Current设置或Ewt.Trace禁用(参见下面的代码),但HttpContextWCF 中没有。

private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
{
    if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
    {
        EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
    }
   ...
   ...
}

尝试禁用跟踪,也许它会有所帮助。

于 2012-08-02T10:11:33.267 回答