Hi am trying this code
public String GetItemUrl(Item item)
{
Sitecore.Links.UrlOptions urlOptions = (Sitecore.Links.UrlOptions)Sitecore.Links.UrlOptions.DefaultOptions.Clone();
urlOptions.SiteResolving = true;
return Sitecore.Links.LinkManager.GetItemUrl(item,urlOptions);
}
ViewBag.thisurl = GetItemUrl(item)
and then from cshtml
a href="@ViewBag.thisURL" .....
When I click on the link, this will always point to CD database and I am not able to edit in page editor. I need to edit the target after i click the link in page editor. Can some one suggest me?
You use SiteResolving, are you running CMS and CD on one server? so they have the same web.config and the hostnames in the sites web.config section point always to CD. SiteResolving explained
There are multiple options.
1) Make a condition and set SiteResolving off in page edit mode. something like this:
public String GetItemUrl(Item item)
{
Sitecore.Links.UrlOptions urlOptions = (Sitecore.Links.UrlOptions)Sitecore.Links.UrlOptions.DefaultOptions.Clone();
if (Sitecore.Context.PageMode.IsPageEditor || Sitecore.Context.PageMode.IsPreview)
{
//depend on your site configuration this is a idea
urlOptions.SiteResolving = false;
}
else
{
urlOptions.SiteResolving = true;
}
return Sitecore.Links.LinkManager.GetItemUrl(item,urlOptions);
}
2) Create your own Sitecore LinkProvider to change the behavior see this example Create a Sitecore LinkProvider to use different LinkManager configurations