There are two different reasons for ugly URL's on in presentation mode:
There is a solution for both problems. Problem 1 requires an additional postback to the server to retrieve the page with the nice looking URL and the second problem can be avoided by adding some code to prevent the postback to the ugly URL by replacing the postback URL with the nice looking one.
Solution for Problem 1:
1) Add the following code part to global.asax.cs of you template project:
public void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { // // correct the url after switch to live // Posting thisPosting = CmsHttpContext.Current.Posting; PublishingMode currentMode = CmsHttpContext.Current.Mode; if (thisPosting != null && currentMode == PublishingMode.Published) { if ( Request.QueryString["NRORIGINALURL"] != null && Request.QueryString["NRORIGINALURL"].StartsWith("/NR/exeres") ) // oh so ugly { if ( !thisPosting.Url.StartsWith("/NR/exeres") ) Response.Redirect (thisPosting.Url); } } }
2) Wire up this event in the global init:
this.PreRequestHandlerExecute += new EventHandler(this.Application_PreRequestHandlerExecute);
The complete implemetation looks like this:
namespace ... { /// /// Summary description for Global. /// public class Global : System.Web.HttpApplication { public Global() { InitializeComponent(); this.PreRequestHandlerExecute += new EventHandler(this.Application_PreRequestHandlerExecute); } public void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { // // correct the url after switch to live // Posting thisPosting = CmsHttpContext.Current.Posting; PublishingMode currentMode = CmsHttpContext.Current.Mode; if (thisPosting != null && currentMode == PublishingMode.Published) { if ( Request.QueryString["NRORIGINALURL"] != null && Request.QueryString["NRORIGINALURL"].StartsWith("/NR/exeres") ) // oh so ugly { if ( !thisPosting.Url.StartsWith("/NR/exeres") ) Response.Redirect (thisPosting.Url); } } } ... } }
Solution for Problem 2:
Add the following code behind the
<% if (WebAuthorContext.Current.Mode == WebAuthorContextMode.PresentationPublished) { %> <SCRIPT language=javascript> <!-- __CMS_PostbackForm.action = '<% =Microsoft.ContentManagement.Publishing.CmsHttpContext.Current.Posting.Url %>'; // --> </SCRIPT> <% } %>