Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

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 ExtensionsModulesModulesDynamic loaded module,  UserID = -1Dynamic loaded module, UserID = -1
Previous
 
Next
New Post
7/18/2012 5:38 PM
 

Hello,

I am having some issues in creating a class property to retrieve the current user logged in ID. From one of my custom modules, when it accesses this property, it returns the correct value for the current user's ID, but when called from another custom module, it returns -1. In debug mode, I can go to one DNN page with module A that works and then to the other page that has module B that returns -1.

In thinking about it, module B is dynamically loaded via jquery and a web method on the same page as module A. It must be because that control is dynamically loaded so the usercontroller doesn't know the current user???

Anyway around this?

Thanks in advance,
Chad

Here is a portion of my class

using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;

using Microsoft.VisualBasic;

using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Roles;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Services.Mail;
using System.Data;

namespace Incite.Modules.InciteCore.Components
{

    public class DNNSecurity
    {
        static int _currentdnnuserid = 0;

        #region "Properties"

       public int CurrentUserID {
       get { _currentdnnuserid = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().UserID;   
       return _currentdnnuserid;
       }
                set
                {
                    HttpContext.Current.Session["UserID"] = value;
                    _currentdnnuserid = value; 
                }
       }

       #endregion
}
}

And here is my web method that loads the control:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MovieRotation.Components;
using MovieRotation.Controls;

namespace MovieRotation.AJAX
{
    /// <summary>
    /// Summary description for Utilities
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class Utilities : System.Web.Services.WebService
    {

        [WebMethod(EnableSession = true)]
        public string LoadUserControl(string mode, string controlPath)
        {
            using (Page page = new Page())
            {
                //This is the generic version, but to access a public property of that control, you need to create
                //it as the class specific to that user control. then you can set the public property of it.
                //UserControl userControl = (UserControl)page.LoadControl(controlPath);
                MovieResults userControl = (MovieResults)page.LoadControl(controlPath);
                
                userControl.mode = mode;
                userControl.ID = "uc" + mode;

                //(userControl.FindControl("lblMessage") as Label).Text = message;
                HtmlForm form = new HtmlForm();
                ScriptManager scriptManager = new ScriptManager();
                form.Controls.Add(scriptManager);
                form.Controls.Add(userControl);
                    
                page.Controls.Add(form);
                using (StringWriter writer = new StringWriter())
                {
                    
                    HttpContext.Current.Server.Execute(page, writer, false);

                    string outputToReturn = writer.ToString();
                    //outputToReturn = outputToReturn.Substring(outputToReturn.IndexOf("<div>"));
                    //outputToReturn = outputToReturn.Substring(0, outputToReturn.IndexOf("</form>"));

                    return outputToReturn;
                }
            }
        }
    }
}


 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDynamic loaded module,  UserID = -1Dynamic loaded module, UserID = -1


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.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out