Try our conversational search powered by Generative AI!

EpiServer 5 : Hangs on Save + Publish using DataFactory

Vote:
 

Hi all,

I'm having a little problem getting some code to work when a user clicks Save and Publish after editting a page. Essentially I am automatically replacing some text in the pages content with some default properties set on the root page.

Everything appears to be working find, and I have done everything correctly - as far as I can tell; however on clicking Save and Publish, EpiServer will "hang" or "freeze" on the pages "view" tab. Links aren't clickable until I hit F5. After hitting F5 everything works again, and my code has successfully replaces the text.

Here is the method I have added to the Global.asax.cs file:

private void CustomSave(object sender, PageEventArgs e)
		{
			PageData pageData = e.Page.CreateWritableClone();
			PageData startPageData = DataFactory.Instance.GetPage(new PageReference(PageReference.StartPage.ID));
			string searchText = startPageData.Property["SearchTerm"] != null
			                    	? startPageData.Property["SearchTerm"].Value.ToString()
			                    	: String.Empty;
			string replaceText = startPageData.Property["TermTextReplace"] != null
									? startPageData.Property["TermTextReplace"].Value.ToString()
			                     	: String.Empty;
			string linkText = startPageData.Property["TermUrl"] != null
									? startPageData.Property["TermUrl"].Value.ToString()
			                     	: String.Empty;
			string openInNewWindow = String.Empty;

			if (pageData.Property["Mainbody"] != null)
			{
				string mainBodyText = pageData.Property["Mainbody"].Value.ToString();

				//Replace
				if (searchText.Length > 0 && mainBodyText.Contains(searchText))
				{
					if (replaceText.Length > 0)obtHlMrnncxcfMLTdr7j
					{
						mainBodyText = mainBodyText.Replace(searchText, !string.IsNullOrEmpty(linkText) ? string.Format("<a href=\"{0}\" target=\"{1}\">{2}</a>", linkText, openInNewWindow, replaceText) : replaceText);
					}
				}

				pageData.Property["Mainbody"].Value = mainBodyText;
				DataFactory.Instance.Save(pageData, SaveAction.Publish);
			}
		}
 
Is there something extra I should do after "DataFactory.Instance.Save(pageData, SaveAction.Publish);"?
 
Thanks for any help,
Henrik

    

    

#49679
Mar 28, 2011 16:42
Vote:
 

OK - I just thought it might be the popup blocker. I'm using Chrome and didn't get a info bar. Turned off popup blocking and EpiServer did show me the conflict resolution form. Just need to figure out how to get round that automatically.

Cheers.

#49680
Mar 28, 2011 16:54
Vote:
 

Are you infinitlely looping?  Any chance you're calling Save/Publish some inside a method which hooks Save or Publish?

(Not that I've ever done anything like that...  :-)

#49681
Mar 28, 2011 18:06
Vote:
 

@Deane: Your exactly right - doh! It is stuck in a loop.

I wrapped the "DataFactory.Instance.Save(pageData, SaveAction.Publish);" code bit with if (pageData.IsModified), which seems to do the trick.

I guess I'm just wondering now if there is a better way. It seems to save OK, but I have to refresh the page once it goes back to the view tab.

Cheers 

#49702
Mar 29, 2011 11:24
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.