More in this section

Forums / Bugs & Issues / Missing current principal.

Missing current principal.

2 posts, 0 answered
  1. ashok
    ashok avatar
    1 posts
    Registered:
    28 Jun 2011
    28 Jun 2011
    Link to this post
    Hi

    I m sending my code which is given below i m using this code to find the page title of given pageid its working fine whe i use in aspx.cs file but show error :Missing current principal. when using global.asax page.

    I m using method getPageName(Pagedetails.page_id);for finding page title pass here page id and get page title its working fine in normal aspx.cs file but show error in global.asax

    Code is given below


    using

     

     

    System;

     

    using

     

     

    System.Collections.Generic;

     

    using

     

     

    System.Linq;

     

    using

     

     

    System.Web;

     

    using

     

     

    System.Web.Security;

     

    using

     

     

    System.Web.SessionState;

     

    using

     

     

    System.IO;

     

    using

     

     

    System.Security.Cryptography;

     

    using

     

     

    System.Text;

     

    using

     

     

    System.Net.Mail;

     

    using

     

     

    System.Net;

     

    using

     

     

    SitefinityWebApp.DAL;

     

    using

     

     

    SitefinityWebApp.Custom.Common;

     

    using

     

     

    SitefinityWebApp.Custom.UserProfile;

     

    using

     

     

    Telerik.Sitefinity;

     

    using

     

     

    Telerik.Web.UI;

     

    using

     

     

    Telerik.Sitefinity.Model;

     

    using

     

     

    Telerik.OpenAccess;

     

    using

     

     

    Telerik.Sitefinity.Security;

     

    using

     

     

    Telerik.Sitefinity.Web;

     

    using

     

     

    Telerik.Sitefinity.Modules.Pages;

     

    using

     

     

    Telerik.Sitefinity.Pages.Model;

     

    namespace

     

     

    SitefinityWebApp

     

    {

     

     

    public class Global : System.Web.HttpApplication

     

    {

     

     

     

    protected void Application_Start(object sender, EventArgs e)

     

    {

    AuctionTimer();

    }

     

     

    private void AuctionTimer()

     

    {

    System.Timers.

     

    Timer _timer = new System.Timers.Timer();

     

     

     

    //_timer.Interval = Convert.ToDouble(TimeSpan.FromSeconds(1));

     

     

     

    //// 60 * 1000 for 1 minute

     

     

     

    //// 1000 for 1 second

     

     

     

    ////_timer.Interval = 60 * 1000 * 60;

     

    _timer.Interval = 60 * 1000 * 2;

    _timer.Elapsed +=

     

    new System.Timers.ElapsedEventHandler(timer_Elapsed);

     

    _timer.Start();

    }

     

     

     

    public void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

     

    {

     

     

    DateTime CurrTime = DateTime.Now;

     

     

     

    string Timewithhoursandmin = String.Format("{0:HH}", CurrTime);

     

     

     

    if (Timewithhoursandmin.IndexOf("15") >= 0)

     

    {

     

     

    CasasAccessLayerDataContext db = new CasasAccessLayerDataContext();

     

     

     

    var PageList = from ctry in db.pagerevisits

     

    .Where(ctry => ctry.revisit_dt ==

     

    Convert.ToDateTime(System.DateTime.Now.AddDays(1).ToShortDateString()))

     

     

     

    select ctry;

     

     

     

    if (PageList.Count() > 0)

     

    {

     

     

    foreach (var Pagedetails in PageList)

     

    {

     

     

    Guid currentUserId = new Guid(Pagedetails.assigneduser_id);

     

     

     

    var userManager = UserManager.GetManager("Default");

     

     

     

    var user = userManager.GetUser(currentUserId);

     

     

     

    // HttpContext.Current.User = System.Security.Principal.WindowsIdenti;

     

     

     

    var dddd = System.Threading.Thread.CurrentPrincipal;

     

     

     

    if (user != null)

     

    {

     

     

    var userEmail = user.Email;

     

     

     

    var userEmailExist = userManager.EmailExists(userEmail);

     

     

     

    string pageTitle = getPageName(Pagedetails.page_id);

     

     

     

     

    DateTime pageDate = Pagedetails.revisit_dt;

     

     

     

    if (userEmailExist == true)

     

    {

     

     

    //build the body

     

     

     

    string emailsub = "CASAS Revisite Page";

     

     

     

    var emailBody = new StringBuilder();

     

     

     

    // emailBody.Append("Dear kindly visit the page " + ":" + pageTitle + "from date" + ":" + pageDate + "<br />");

     

    emailBody.Append(

     

    "Dear kindly visit the page from date" + ":" + string.Format("{0:d}",pageDate) + "<br />");

     

    emailBody.AppendFormat(

     

    "Regards<br />");

     

    emailBody.AppendFormat(

     

    "Casas Team");

     

     

     

    Utils.sendEmail(userEmail, "", "", "noreply@idhasoft.com", "Casas Service", emailsub, emailBody.ToString());

     

    }

    }

    }

    }

    }

    }

     

     

    public string getPageName(string _id)

     

    {

     

     

    Guid currentPageId = new Guid(_id);

     

     

     

    if (_id != null)

     

    {

     

     

    PageManager pManager = PageManager.GetManager();

     

     

     

    var page = pManager.GetPageNode(currentPageId);//Error comes

     

    using

     

     

    System;

     

     

     

     

    using

     

     

    System.Collections.Generic;

     

     

     

     

    using

     

     

    System.Linq;

     

     

     

     

    using

     

     

    System.Web;

     

     

     

     

    using

     

     

    System.Web.Security;

     

     

     

     

    using

     

     

    System.Web.SessionState;

     

     

     

     

    using

     

     

    System.IO;

     

     

     

     

    using

     

     

    System.Security.Cryptography;

     

     

     

     

    using

     

     

    System.Text;

     

     

     

     

    using

     

     

    System.Net.Mail;

     

     

     

     

    using

     

     

    System.Net;

     

     

     

     

    using

     

     

    SitefinityWebApp.DAL;

     

     

     

     

    using

     

     

    SitefinityWebApp.Custom.Common;

     

     

     

     

    using

     

     

    SitefinityWebApp.Custom.UserProfile;

     

     

     

     

    using

     

     

    Telerik.Sitefinity;

     

     

     

     

    using

     

     

    Telerik.Web.UI;

     

     

     

     

    using

     

     

    Telerik.Sitefinity.Model;

     

     

     

     

    using

     

     

    Telerik.OpenAccess;

     

     

     

     

    using

     

     

    Telerik.Sitefinity.Security;

     

     

     

     

    using

     

     

    Telerik.Sitefinity.Web;

     

     

     

     

    using

     

     

    Telerik.Sitefinity.Modules.Pages;

     

     

     

     

    using

     

     

    Telerik.Sitefinity.Pages.Model;

     

     

     

     

    namespace

     

     

    SitefinityWebApp

     

    {

     

     

    public class Global : System.Web.HttpApplication

     

     

     

     

     

    {

     

     

     

    protected void Application_Start(object sender, EventArgs e)

     

    {

    AuctionTimer();

    }

     

     

    private void AuctionTimer()

     

    {

    System.Timers.

     

    Timer _timer = new System.Timers.Timer();

     

     

     

    //_timer.Interval = Convert.ToDouble(TimeSpan.FromSeconds(1));

     

     

     

     

     

     

     

    //// 60 * 1000 for 1 minute

     

     

     

     

     

     

     

    //// 1000 for 1 second

     

     

     

     

     

     

     

    ////_timer.Interval = 60 * 1000 * 60;

     

     

     

     

     

    _timer.Interval = 60 * 1000 * 2;

    _timer.Elapsed +=

     

    new System.Timers.ElapsedEventHandler(timer_Elapsed);

     

    _timer.Start();

    }

     

     

     

    public void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

     

    {

     

     

    DateTime CurrTime = DateTime.Now;

     

     

     

    string Timewithhoursandmin = String.Format("{0:HH}", CurrTime);

     

     

     

    if (Timewithhoursandmin.IndexOf("15") >= 0)

     

    {

     

     

    CasasAccessLayerDataContext db = new CasasAccessLayerDataContext();

     

     

     

    var PageList = from ctry in db.pagerevisits

     

    .Where(ctry => ctry.revisit_dt ==

     

    Convert.ToDateTime(System.DateTime.Now.AddDays(1).ToShortDateString()))

     

     

     

    select ctry;

     

     

     

    if (PageList.Count() > 0)

     

    {

     

     

    foreach (var Pagedetails in PageList)

     

    {

     

     

    Guid currentUserId = new Guid(Pagedetails.assigneduser_id);

     

     

     

    var userManager = UserManager.GetManager("Default");

     

     

     

    var user = userManager.GetUser(currentUserId);

     

     

     

    // HttpContext.Current.User = System.Security.Principal.WindowsIdenti;

     

     

     

     

     

     

     

    var dddd = System.Threading.Thread.CurrentPrincipal;

     

     

     

    if (user != null)

     

    {

     

     

    var userEmail = user.Email;

     

     

     

    var userEmailExist = userManager.EmailExists(userEmail);

     

     

     

    string pageTitle = getPageName(Pagedetails.page_id);

     

     

     

     

    DateTime pageDate = Pagedetails.revisit_dt;

     

     

     

    if (userEmailExist == true)

     

    {

     

     

    //build the body

     

     

     

     

     

     

     

    string emailsub = "CASAS Revisite Page";

     

     

     

    var emailBody = new StringBuilder();

     

     

     

    // emailBody.Append("Dear kindly visit the page " + ":" + pageTitle + "from date" + ":" + pageDate + "<br />");

     

     

     

     

     

    emailBody.Append(

     

    "Dear kindly visit the page from date" + ":" + string.Format("{0:d}",pageDate) + "<br />");

     

    emailBody.AppendFormat(

     

    "Regards<br />");

     

    emailBody.AppendFormat(

     

    "Casas Team");

     

     

     

    Utils.sendEmail(userEmail, "", "", "noreply@idhasoft.com", "Casas Service", emailsub, emailBody.ToString());

     

    }

    }

    }

    }

    }

    }

     

     

    public string getPageName(string _id)

     

    {

     

     

    Guid currentPageId = new Guid(_id);

     

     

     

    if (_id != null)

     

    {

     

     

    PageManager pManager = PageManager.GetManager();

     

     

     

    var page = pManager.GetPageNode(currentPageId);//error here Missing current principal.

     

     

     

    return page.Title;

     

    }

     

     

    else

     

     

     

     

     

    {

     

     

    return string.Empty;

     

    }

    }

     

     

     

    protected void Session_Start(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_BeginRequest(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_AuthenticateRequest(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_Error(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Session_End(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_End(object sender, EventArgs e)

     

    {

    }

    }

    }

     

     

    return page.Title;

     

    }

     

     

    else

     

    {

     

     

    return string.Empty;

     

    }

    }

     

     

     

    protected void Session_Start(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_BeginRequest(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_AuthenticateRequest(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_Error(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Session_End(object sender, EventArgs e)

     

    {

    }

     

     

    protected void Application_End(object sender, EventArgs e)

     

    {

    }

    }

    }


    If any solution please send me waiting your response it very neede for me

    Regards
    Ashok

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jun 2011
    Link to this post
    Hi ashok,

    Could you check whether the error is thrown when you are authenticated. Also you can use Sitefinity's specific principal.


              var userId = SecurityManager.GetCurrentUserId();
              var user = UserManager.GetManager().GetUser(userId);
              var principal = new SitefinityPrincipal(new UserIdentity(user));

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered