定制会话状态提供程序初始化期间的对象引用

时间:2011-10-07 09:47:32

标签: asp.net iis-6 session-state-provider

我编写了一个自定义会话状态提供程序,它在调试模式下工作正常,但一旦部署在服务器(IIS 6)上,我就会收到以下错误:

Event code: 3008 
Event message: A configuration error has occurred. 
Event time: 10/7/2011 3:05:02 PM 
Event time (UTC): 10/7/2011 9:35:02 AM 
Event ID: 00e2c8b1368b45608bb062eb2ba9d0db 
Event sequence: 2 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/Root/bizapp-1-129624536989844520 
    Trust level: Full 
    Application Virtual Path: ...
    Application Path: ...
    Machine name: ...

Process information: 
    Process ID: 7556 
    Process name: w3wp.exe 
    Account name: ...

Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: Object reference not set to an instance of an object. (E:\Program Files\BizAPP\WebClient\web.config line 282) 

Request information: 
    Request URL: http://localhost:8080/bizapp/login.aspx 
    Request path: /bizapp/login.aspx 
    User host address: 127.0.0.1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: ...

Thread information: 
    Thread ID: 1 
    Thread account name: ...
    Is impersonating: False 
    Stack trace:    at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
   at System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSection config)
   at System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication app, SessionStateSection config)
   at System.Web.SessionState.SessionStateModule.Init(HttpApplication app)
   at System.Web.HttpApplication.InitModulesCommon()
   at System.Web.HttpApplication.InitModules()
   at System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers)
   at System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context)
   at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
   at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)

修改 第282行来自web.config,其中包含提供者信息,第3行位于

之下
<sessionState mode="Custom" customProvider="SessionStateStoreProvider" timeout="180">
            <providers>
                <add name="SessionStateStoreProvider" type="type full name" />
            </providers>
        </sessionState>

2 个答案:

答案 0 :(得分:1)

这意味着“对象引用未设置为对象的实例”异常发生在您的某个提供程序的方法中(例如,在Initialize方法中)。该代码中存在一个错误。

所以你可以在那里放置一个断点并调试,或者用一个可以在文本中转换异常的try catch来覆盖重写的方法,如下所示:

public class YourSessionState : SessionStateStoreProviderBase
{
    public override void Initialize(string name, NameValueCollection config)
    {
        try
        {
            // your original Initialize code here
        }
        catch (Exception e)
        {
            throw new Exception("Error in initialize: " + e);
        }
    }
}

如果将.PDB文件放在.DLL旁边,您现在应该看到错误行号。

答案 1 :(得分:-1)

您未在配置中正确指定类型

示例:

<sessionState mode="Custom" customProvider="SessionStateStoreProvider">
  <providers>
    <add name="SessionStateStoreProvider"
         type="Namespace.To.Your.SessionStateStoreClass" />
  </providers>
</sessionState>

除非您故意省略该类型。