Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAJAX Module Using DnnApiController Service, Session is NULLAJAX Module Using DnnApiController Service, Session is NULL
Previous
 
Next
New Post
9/11/2013 4:25 PM
 

Hello!  We're working on using AJAX with a particular module.  It has come to our attention to write the back end service(s) using the DnnApiController service infrastructure. (Using DNN 7.x)

    [SupportedModules("ModuleXYZ")]
    public class ModuleXYZAJAXViewController : DnnApiController
    {
        [AllowAnonymous]
        [HttpGet]
        public HttpResponseMessage GetData()
        {
            string output = HttpContext.Current.Session["example"]; //ALWAYS IS NULL within this SCOPE/CONTEXT

            return Request.CreateResponse(HttpStatusCode.OK, output);
        }
    }

This back end code when called, works as predicated.  What fails is that within this scope the session reference is always null.  The session reference is not null anywhere else in any of the .ascx files.  Because of this issue, I have adjusted the routing to add in the session context to the request as well, alas this is not working.

 I have included my routing code as well on how I was attempting to extend the session layer into the WebAPI.

public class ModuleXYZViewService : IServiceRouteMapper
{
    public void RegisterRoutes(IMapRoute mapRouteManager)
    {
        var route = mapRouteManager.MapHttpRoute("ModuleXYZ", "default", "{controller}/{action}",
            new[] { "ModuleXYZ.Ajax" });
        foreach (Route r in route)
        {
            r.RouteHandler = new SessionBasedControllerRouteHandler();
        }
    }
    public class SessionBasedControllerHandler : HttpControllerHandler, IRequiresSessionState
    {
        public SessionBasedControllerHandler(RouteData routeData) : base(routeData)
        {
        }
    }
    public class SessionBasedControllerRouteHandler : HttpControllerRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return new SessionBasedControllerHandler(requestContext.RouteData);
        }
    }
}

Believe you-me, I don't like trying to extend the session tier into a web method.  But given the case of making a flexible AJAX service and keeping it secure, the session tier needs to be still in tact.  The only other solution would be encrypting my payload during page load and passing it into the AJAX call in hopes that someone on the outside wouldn't figure out.  Any thoughts or ideas on a solution of extending the session layer such that it is not null in the scope and context of the Web API?  This is a known design limitation with the core ApiController of .Net.  I look at it as not a bug, but a proper way of doing web APIs.

 

 
New Post
1/4/2014 1:28 PM
 
I did it the same way as you have done , and it is working perfectly using DNN 7.0.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAJAX Module Using DnnApiController Service, Session is NULLAJAX Module Using DnnApiController Service, Session is NULL


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  


Copyright 2017 by DNN Corp Terms of Use Privacy
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out