我在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:\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>发布于 2012-08-02 18:11:33
当您使用自定义配置文件提供程序并且未将其设置为默认提供程序时,可能会发生此异常。检查是否在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);
}
...
...
}试着禁用跟踪,也许会有帮助。
https://stackoverflow.com/questions/11774516
复制相似问题