Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Create a new page instance (following line fails with "Access was denied to page 25")
PageData newPage = Global.EPDataFactory.GetDefaultPageData(CurrentPage.PageLink, pageType.ID, EPiServer.Security.AccessControlList.NoAccess);
// Set details for the page
newPage.PageName = "Comment created on " + DateTime.Now.ToString("R");
newPage.VisibleInMenu = false;
((PropertyString)newPage.Property["CommentName"]).Value = txtCommentName.Text;
((PropertyString)newPage.Property["CommentEmail"]).Value = txtCommentEmail.Text;
((PropertyLongString)newPage.Property["CommentText"]).Value = HttpUtility.HtmlEncode(txtCommentText.Text);
// Now save the page
Global.EPDataFactory.Save(newPage, EPiServer.DataAccess.SaveAction.Save, EPiServer.Security.AccessControlList.NoAccess);
}
protected void btnSubmit_Click(object sender, EventArgs e) { // Save the current user details UnifiedPrincipal currentUser = UnifiedPrincipal.Current; // Get our 'Auto create' user details from config string userName = SiteSettings.GetSettingString("AutomaticCreatorUserName"); string password = SiteSettings.GetSettingString("AutomaticCreatorPassword"); // Obtain the Iprincipal IPrincipal principal = AuthenticationProvider.Authenticate(this, userName, password); // Set the CurrentUSer to this one PageBase.CurrentUser = principal as UnifiedPrincipal; // Load the required page type PageType pageType = PageType.Load(Names.PageTypeNewsComment); // Create a new page instance (following line fails with "Access was denied to page 25") PageData newPage = Global.EPDataFactory.GetDefaultPageData(CurrentPage.PageLink, pageType.ID); // Set details for the page newPage.PageName = "Comment created on " + DateTime.Now.ToString("R"); newPage.VisibleInMenu = false; ((PropertyString)newPage.Property["CommentName"]).Value = txtCommentName.Text; ((PropertyString)newPage.Property["CommentEmail"]).Value = txtCommentEmail.Text; ((PropertyLongString)newPage.Property["CommentText"]).Value = HttpUtility.HtmlEncode(txtCommentText.Text); // Now save the page Global.EPDataFactory.Save(newPage, EPiServer.DataAccess.SaveAction.Save); // And 'restore' previous user PageBase.CurrentUser = currentUser; }
Any ideas? Regards, Mark