Results 1 to 2 of 2

Thread: injecting httpContext.Session into a spring.net enabled ashx page

  1. #1
    Join Date
    May 2010
    Location
    Belfast, United Kingdom
    Posts
    4

    Question injecting httpContext.Session into a spring.net enabled ashx page

    Last year I posted a similar problem in http://forum.springframework.net/sho...yer-webservice I am now trying to do the same thing with an ashx page. Using Spring version 1.3

    I have an ashx page in the presentation layer using spring.net and nHibernate in the typical configuration of presentation layer <- Web.xml -> Business Layer <- Business.xml -> Data Access layer.

    I presume I need to do something similar to the solution mentioned above, but I am having no luck.

    Code:
    <!-- START ashx pages -->
      <object id="gencsvSession" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
        <property name="TargetName" value="gencsv"/>
        <property name="MemberAttributes">
          <dictionary>
            <entry key="*">
              <!-- '*' for all methods or use the method name : <entry key="submitTest"> -->
              <object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
                <property name="EnableSession" value="true"/>
              </object>
            </entry>
          </dictionary>
        </property>
      </object>
    
      <object name="gencsv" type="Tissuebank.gencsv, Tissuebank">
        <property name="TBCPRSampleBLL" ref="TBCPRSampleBLL"></property>
        <property name="UserBLL" ref="UserBLL"></property>
      </object>
      <!-- END of ashx pages -->
    In the ashx page
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.SessionState;
    using spring.pxl.Domain;
    using BusinessLayer;
    using log4net;
    Method that accesses the session

    Code:
    private void _canViewPage(HttpContext context)
            {
                logger.Debug(writeerror.rs_logmethodLM());
                string a = Convert.ToString(context.Session["uid"]);
    and I get the following error

    Code:
    Server Error in '/' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. 
    Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    Source Error:
    
    Line 107:        {
    Line 108:            logger.Debug(writeerror.rs_logmethodLM());
    Line 109:            string a = Convert.ToString(context.Session["uid"]);
    
    
    Source File: ..\gencsv.ashx.cs    Line: 109
    
    Stack Trace:
    
    [NullReferenceException: Object reference not set to an instance of an object.]
       Tissuebank.gencsv._canViewPage() in ..\gencsv.ashx.cs:109
       Tissuebank.gencsv.ProcessRequest(HttpContext context) in ..\gencsv.ashx.cs:37
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

  2. #2
    Join Date
    Dec 2010
    Posts
    2

    Default

    Try to use this:

    if (HttpContext.Current.Session != null)
    {
    HttpContext.Current.Session["customVariable"].ToString();
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •