我正在使用 response.redirect 来保存 url,它在同一页面上打开链接,还有什么可以在新标签中打开链接?
public partial class DocumentLink : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
try
{
Sitecore.Data.Fields.LinkField linkField = SitecoreItem.CurrentItem.Fields["DocumentLink"];
Response.Redirect(GetUrl(linkField));
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error(ex.ToString(), this);
}
}
}
public string GetUrl(Sitecore.Data.Fields.LinkField LinkField)
{
try
{
string url = "";
switch (LinkField.LinkType)
{
case "internal":
case "external":
case "mailto":
case "anchor":
case "javascript":
url = LinkField.Url;
break;
case "media":
MediaItem media = new MediaItem(LinkField.TargetItem);
url = Sitecore.StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(media));
break;
case "":
default:
break;
}
return url;
}
catch (Exception ex)
{
Sitecore.Diagnostics.Log.Error(ex.ToString(), this);
throw;
}
}
}