首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么AuthenticationManager.Login会抛出object not set异常?

为什么AuthenticationManager.Login会抛出object not set异常?
EN

Stack Overflow用户
提问于 2012-08-02 17:21:07
回答 1查看 1.6K关注 0票数 1

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

代码语言:javascript
复制
if (Sitecore.Security.Authentication.AuthenticationManager.Login("sitecore\\" + username, password, false)) 
{ 
  // do something 
} 

但是我得到了一个"Object not set“异常,堆栈跟踪如下:

代码语言:javascript
复制
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的配置文件位:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-02 18:11:33

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

代码语言:javascript
复制
<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

代码语言:javascript
复制
private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
{
    if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8))
    {
        EtwTrace.Trace(EtwTraceType.ETW_TYPE_PROFILE_BEGIN, HttpContext.Current.WorkerRequest);
    }
   ...
   ...
}

试着禁用跟踪,也许会有帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11774516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档