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;
}
}
}
}
}