AI OnAI Off
public bool isInEditMode (PageBase myP)
{
bool ret = false;
if (null != myP.Request.UrlReferrer &&
(myP.Request.UrlReferrer.ToString().IndexOf("edit") >= 0 ||
myP.Request.UrlReferrer.ToString().IndexOf("Edit") >= 0 ||
myP.Request.UrlReferrer.ToString().IndexOf("admin") >= 0 ||
myP.Request.UrlReferrer.ToString().IndexOf("Admin") >= 0))
{
ret = true;
}
return ret;
}
/mats d.
public bool isInEditMode()
{
return Regex.IsMatch(HttpContext.Current.UrlReferrer.LocalPath, "^/admin/|^/edit/", RegexOptions.IgnoreCase);
}
or unless you want to include the uses for System.Web and System.Text.RegularExpressions
public bool isInEditMode()
{
return System.Text.RegularExpressions.Regex.IsMatch(System.Web.HttpContext.Current.UrlReferrer.LocalPath, "^/admin/|^/edit/", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
However none of these function return true if you navigate in Edit-mode by clicking a link on the page in preview. As far as I know there are no really good solution to this problem. One thing one might do is to subclass EPiServer.Edit.PreviewControl (the control used for the iframe in edit mode, and of course change ) and have it add a cookie with a very low expiredate?
using System;
using System.Web;
namespace EPiServer.Edit.MyOwnReplacement
{
public class PreviewControl : EPiServer.Edit.PreviewControl
{
private void Page_PreRender(object sender, EventArgs e)
{
if (PreviewUrl.LastIndexOf('?') != -1)
{
PreviewUrl += "&mode=preview";
}
else
{
PreviewUrl += "?mode=preview";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.PreRender += new EventHandler(Page_PreRender);
}
#endregion
}
}
then goto /edit/EditPanal.aspx and change the following line to load your modified preview control
<%@ Register TagPrefix="EPiServer" Namespace="EPiServer.WebControls" Assembly="EPiServer" %>
to
<%@ Register TagPrefix="edit" TagName="PreviewControl" Src="~/ThePathAndNameOfTheControl.aspx"%>