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 ExtensionsModulesModulesUserInfo.UserID = -1 when logged in?UserInfo.UserID = -1 when logged in?
Previous
 
Next
New Post
7/28/2012 11:57 PM
 

Hello,
I have a custom module that within it dynamically loads another user control via jquery/ajax. When that control loads, stepping through the code, the UserInfo.UserID value is always -1 when the control is loaded dynamically. 

I assume that this has something to do with the dynamically loaded control not being "aware" of the DNN base when loaded like this, similar to how you also need to explicitly put  [WebMethod(EnableSession = true)] in front of the webmethod in order for it to know about the Session. 

Is there some way to pass the DNN info to the webmethod so it is aware of it? Or am I best served by storing the current user in a session variable instead?

Thanks in advance,
Chad

 
New Post
7/29/2012 1:18 AM
Accepted Answer 
Web services do not have a "web context", that is created when a person goes to a url that maps to a portal and the person logs in, so you do not have a "logged in user".

Leigh Pointer
User Group Champion [World Wide]
» Evangelising DotNetNuke Everywhere «

Nederlandstalige DotNetNuke Gebruikersgroep Subzero Solutions ARC for DotNetNuke Design is the craft of visualising concrete solutions that serve human needs and goals within certain contraints. Visulising concrete solutions is the essence of design.
 
New Post
7/30/2012 11:20 AM
 
Thanks for the answer Leigh. I will have to use session variables instead.
 
New Post
7/31/2012 5:13 AM
 

Hi Chad

 You can also use code belove to load user control with additional parameters:

/// <summary>
/// Loads user control with parameters
/// </summary>
private Control LoadControl(string userControlPath, params object[] constructorParameters) {
            List<Type> constParamTypes = new List<Type>();

            for (int i = 0; i < constructorParameters.Length; i++)
                constParamTypes.Add(constructorParameters[i].GetType());

            Control ctl = Page.LoadControl(userControlPath);
            ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
            if (constructor == null)
                throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
            else
                constructor.Invoke(ctl, constructorParameters);
            return ctl;
}

 //to execute method above

this.LoadControl(this.ControlPath + @"/Controls/MyCustomControl.ascx", this.UserID)

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUserInfo.UserID = -1 when logged in?UserInfo.UserID = -1 when logged in?


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