WCF服务背后有以下代码:
if (Sitecore.Security.Authentication.AuthenticationManager.Login("sitecore\" + username, password, false))
{
// do something
}
但我得到了一个"Object not set"异常,有以下堆栈跟踪:
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:DevDevelopment-WebsitesMainwebsite2012-DRCodeservicesDR.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>
当您使用自定义配置文件提供程序并且未将其设置为默认提供程序时,可能会发生此异常。检查是否为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
(请参阅下面的代码),但WCF中没有HttpContext
。
private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
{
if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
}
...
...
}
尝试禁用跟踪,也许会有所帮助。